ThreeKingdomsSlingshot/Assets/VFX/GabrielAguiarProductions/Scripts/UniqueProjectiles/ProjectileMoveScript.cs

173 lines
5.2 KiB
C#
Raw Permalink Normal View History

스킬 이펙트 작업 준비 — 스킬 테스트 씬 · WL 이펙트 이식 · 이펙트 표 · 보병·창·기병 슬링샷 공격 = WL 창 돌진 이펙트 시험(PD 2026-11-09) PD 「WL 프로젝트에서 스킬을 구현하던 방식과 동일하게 유닛 별 스킬 구현」 · 「테스트 목적: 보병, 창, 기병을 슬링샷으로 공격할 때 WL 창 돌진 공격 이펙트」 - 스킬 테스트 씬 Assets/Scenes/SkillTest.unity(SkillTestBootstrap · 메뉴 TKS/Skill Test/Build Scene): 영웅 목록 선택(heroes.csv 56) · 더미(죽지 않음 · 행동 토글 · 배치 표 Resources/Skills/skill_test.csv) · 슬링샷 · 액티브 버튼 · 쿨 무시 · 영웅 무적 · 이펙트 보기(에디터 · Assets/VFX 검색 → 영웅에 띄움) - 이펙트 표 Resources/Skills/skill_vfx.csv → Runtime/Skills/SkillVfx(키 = 스킬 id 또는 basic_<병종> · cast/travel/hit · f_every 반복 · 사본 Resources/Fx/TKS_Fx_*) · 훅 = SkillSystem Announce/BeginAction/EndAction/Hit/Instant - WL 이펙트 이식 Assets/VFX(약 640 MB · 빌트인 호환분만 · GUID 유지 · 도구 Tools/wl_vfx_import.py) · URP 셰이더 빌트인 이식 4종 Assets/VFX/_BuiltinPorts · com.unity.shadergraph 17.3.0 · 카메라 깊이 텍스처 켬(셰이더 그래프 소프트 파티클) - 시험: basic_infantry/spear/cavalry travel = TKS_Fx_SpearRush · SpearRushWrap · SpearRushDust(WL WLStaffEarth rushFx 1~3 값 환산) — 표 9행 삭제 = 원래대로 - 테스트 118/118 · console error 0 · 이 PC 첫 임포트 자동 재직렬화(png·tga .meta · UITheme · ProjectSettings · InputManager)는 제외 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 14:12:52 +00:00
//
//
//NOTES:
//
//This script is used for DEMONSTRATION porpuses of the Projectiles. I recommend everyone to create their own code for their own projects.
//THIS IS JUST A BASIC EXAMPLE PUT TOGETHER TO DEMONSTRATE VFX ASSETS.
//
//
#pragma warning disable 0168 // variable declared but not used.
#pragma warning disable 0219 // variable assigned but not used.
#pragma warning disable 0414 // private field assigned but not used.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProjectileMoveScript : MonoBehaviour {
public bool rotate = false;
public float rotateAmount = 45;
public bool bounce = false;
public float bounceForce = 10;
public float speed;
[Tooltip("From 0% to 100%")]
public float accuracy;
public float fireRate;
public GameObject muzzlePrefab;
public GameObject hitPrefab;
public List<GameObject> trails;
private Vector3 startPos;
private float speedRandomness;
private Vector3 offset;
private bool collided;
private Rigidbody rb;
private RotateToMouseScript rotateToMouse;
private GameObject target;
void Start () {
startPos = transform.position;
rb = GetComponent <Rigidbody> ();
//used to create a radius for the accuracy and have a very unique randomness
if (accuracy != 100) {
accuracy = 1 - (accuracy / 100);
for (int i = 0; i < 2; i++) {
var val = 1 * Random.Range (-accuracy, accuracy);
var index = Random.Range (0, 2);
if (i == 0) {
if (index == 0)
offset = new Vector3 (0, -val, 0);
else
offset = new Vector3 (0, val, 0);
} else {
if (index == 0)
offset = new Vector3 (0, offset.y, -val);
else
offset = new Vector3 (0, offset.y, val);
}
}
}
if (muzzlePrefab != null) {
var muzzleVFX = Instantiate (muzzlePrefab, transform.position, Quaternion.identity);
muzzleVFX.transform.forward = gameObject.transform.forward + offset;
var ps = muzzleVFX.GetComponent<ParticleSystem>();
if (ps != null)
Destroy (muzzleVFX, ps.main.duration);
else {
var psChild = muzzleVFX.transform.GetChild(0).GetComponent<ParticleSystem>();
Destroy (muzzleVFX, psChild.main.duration);
}
}
}
void FixedUpdate () {
if (target != null)
rotateToMouse.RotateToMouse (gameObject, target.transform.position);
if (rotate)
transform.Rotate(0, 0, rotateAmount, Space.Self);
if (speed != 0 && rb != null)
rb.position += (transform.forward + offset) * (speed * Time.deltaTime);
}
void OnCollisionEnter (Collision co) {
if (!bounce)
{
if (co.gameObject.tag != "Bullet" && !collided)
{
collided = true;
if (trails.Count > 0)
{
for (int i = 0; i < trails.Count; i++)
{
trails[i].transform.parent = null;
var ps = trails[i].GetComponent<ParticleSystem>();
if (ps != null)
{
ps.Stop();
Destroy(ps.gameObject, ps.main.duration + ps.main.startLifetime.constantMax);
}
}
}
speed = 0;
GetComponent<Rigidbody>().isKinematic = true;
ContactPoint contact = co.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
Vector3 pos = contact.point;
if (hitPrefab != null)
{
var hitVFX = Instantiate(hitPrefab, pos, rot) as GameObject;
var ps = hitVFX.GetComponent<ParticleSystem>();
if (ps == null)
{
var psChild = hitVFX.transform.GetChild(0).GetComponent<ParticleSystem>();
Destroy(hitVFX, psChild.main.duration);
}
else
Destroy(hitVFX, ps.main.duration);
}
StartCoroutine(DestroyParticle(0f));
}
}
else
{
rb.useGravity = true;
rb.linearDamping = 0.5f;
ContactPoint contact = co.contacts[0];
rb.AddForce (Vector3.Reflect((contact.point - startPos).normalized, contact.normal) * bounceForce, ForceMode.Impulse);
Destroy ( this );
}
}
public IEnumerator DestroyParticle (float waitTime) {
if (transform.childCount > 0 && waitTime != 0) {
List<Transform> tList = new List<Transform> ();
foreach (Transform t in transform.GetChild(0).transform) {
tList.Add (t);
}
while (transform.GetChild(0).localScale.x > 0) {
yield return new WaitForSeconds (0.01f);
transform.GetChild(0).localScale -= new Vector3 (0.1f, 0.1f, 0.1f);
for (int i = 0; i < tList.Count; i++) {
tList[i].localScale -= new Vector3 (0.1f, 0.1f, 0.1f);
}
}
}
yield return new WaitForSeconds (waitTime);
Destroy (gameObject);
}
public void SetTarget (GameObject trg, RotateToMouseScript rotateTo)
{
target = trg;
rotateToMouse = rotateTo;
}
}