-
04/15 유니티 LineRenderer 사용 연습유니티 2021. 4. 15. 17:44
LineRendererTest.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LineRendererTest : MonoBehaviour { public Transform fireTrans; public float range = 1f; private LineRenderer line; private void Awake() { this.line = this.GetComponent<LineRenderer>(); } // Start is called before the first frame update public void Shoot() { Debug.Log("shoot"); StartCoroutine(this.ShootImpl()); } public IEnumerator ShootImpl() { line.SetPosition(0, this.fireTrans.position); var pos = this.fireTrans.localPosition; pos.z = this.fireTrans.forward.z * this.range; line.SetPosition(1, pos); line.enabled = true; yield return new WaitForSeconds(0.03f); line.enabled = false; } }
Test5.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test5 : MonoBehaviour { public ParticleSystem eff1; public ParticleSystem eff2; public float cycle = 1f; public LineRendererTest lineRendererTest; // Start is called before the first frame update void Start() { //test.AutoShoot(); } private void Update() { if (Input.GetMouseButton(0)) { StartCoroutine(this.AutoShootImpl()); this.lineRendererTest.Shoot(); } } private IEnumerator AutoShootImpl() { eff1.Play(); eff2.Play(); yield return new WaitForSeconds(cycle); } }
'유니티' 카테고리의 다른 글
04/16 수업내용 메모 (0) 2021.04.16 04/15 유니티 애니메이션 컨트롤러 연습 (0) 2021.04.16 04/15 유니티 화면 클릭으로 이동 구현 연습 (0) 2021.04.15 04/15 유니티 IK 연습 (0) 2021.04.15 04/14 수업내용 메모 (0) 2021.04.14