Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Change game-cursor on gameobjects within range

$
0
0
Hi. I have a problem with the following code: using UnityEngine; using System.Collections; using UnityEngine.EventSystems; public class Move : MonoBehaviour { public bool Cursor_enemy = false; public float radius = 50f; public Collider[] colliders; public LayerMask mask; void LateUpdate() { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); colliders = Physics.OverlapSphere (transform.position, radius, mask); foreach (Collider col in colliders) { if (Physics.Raycast(ray, out hit)) { if (hit.collider == col) { Cursor_enemy = true; } else if (hit.collider != col) { Cursor_enemy = false; } } } if (Cursor_enemy == true) { GameObject.Find ("Canvas").GetComponent ().enemy_target = true; } else { GameObject.Find ("Canvas").GetComponent ().enemy_target = false; } } This code change the game-cursor when it's hovering the first gameobject in the array of colliders found within a radius of 50 units, but it doesn't change the game-cursor when it's hovering any other gameobject that's within 50 units also. Am I using a wrong method here?

Viewing all articles
Browse latest Browse all 184

Trending Articles