Ray-cast only detecting tags in debug.log and not in a if statement
Ok so the problem i am having is that the second debug .log under //2 does not work and never enters the if statement yet the first debug.log under //1 returns the tag "Enemy" any ideas on how to fix ?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class RayCast : MonoBehaviour { public GameObject projectile; public float range; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
RaycastHit hit;
Ray landingRay = new Ray (transform.position, Camera.main.transform.forward);
if (Physics.Raycast (landingRay, out hit, range)) {
//1
Debug.Log(hit.transform.tag);
if (hit.transform.tag == "Enemy") {
//2
Debug.Log(hit.transform.tag);
print ("enemy");
}
Debug.DrawLine (transform.position, hit.point);
}
}
}
Comment
Enemy is written correct? any space at the end of the tag it hidden character?
Your answer
Follow this Question
Related Questions
Use enum hidden value as something other than int? (C#) 2 Answers
RayCast enemy hp 0 Answers
Mesh based gravity 2 Answers
Raycast to an area, not a point 3 Answers
Select Objects without Collider? 0 Answers