Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Ray Cast Click on Enemy - Change Current Target

$
0
0
My raycast target enemy works perfect, my only problem is when I have a target the only way to untarget is to kill the enemy or to right click. I want to make it so if I have a target and i choose to click another one, the target will change. Cant figure it out! void Update () { if( Input.GetMouseButtonDown(0) && newon == true) { Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition ); RaycastHit hit; if( Physics.Raycast( ray, out hit, 100 ) ) { float distance = Vector3.Distance(hit.transform.position, transform.position); if(distance < 8) { string hitTag = hit.transform.tag; if (hitTag == "enemy" && newon == true) { Debug.Log( hit.transform.gameObject.name ); target = hit.transform.gameObject; SelectTarget(); } } } } if (Input.GetMouseButtonDown (1)) { DeselectTarget(); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>