Quantcast
Channel: Questions in topic: "drawray"
Viewing all articles
Browse latest Browse all 92

Raycast registering hit when the player touches the target gameobject

$
0
0
I'm kinda new in unity and still figuring out few things. in this project I'm trying to do things when the raycast hit the target but it does not registers the hit when the ray hits the target but registers hit when the player gameobject touches the player. ---------- using System.Collections; using System.Collections.Generic; using UnityEngine; public class FOV_Sc : MonoBehaviour { public LayerMask layerMask; public float range; PlayerMovement_Sc playerMovement_Sc; float characterDireciton; // Start is called before the first frame update void Start() { playerMovement_Sc = GetComponent(); playerMovement_Sc.characterDirection = characterDireciton; } // Update is called once per frame void Update() { RaycastHit2D hit2D = Physics2D.Raycast(gameObject.transform.position, Vector2.right * new Vector2(characterDireciton, 0f), range, layerMask); Debug.DrawRay(gameObject.transform.position, Vector2.right * new Vector2(characterDireciton, 0f), Color.white); if (hit2D.collider.transform) { Debug.Log(hit2D.collider.transform.name+" "+hit2D.collider.transform.tag); Debug.DrawRay(gameObject.transform.position, Vector2.right , Color.red); } else { Debug.Log("NOt enemy"); Debug.DrawRay(gameObject.transform.position, Vector2.right * new Vector2(characterDireciton, 0f), Color.green); } } }

Viewing all articles
Browse latest Browse all 92

Latest Images

Trending Articles





Latest Images