I have a scene where I have several different shapes.
Attached to an object is a script containing the raycast stuff.
When the ray intersects an object of a certain shape, I want it do show the shape that it has intersected.
For some reason, It will work the first time but as soon as I move off a shape, the raycast seems to do nothing and it wont recognize that its hit again the second time.
It has me stumped cause I have used raycasts before and not run into this problem. It appears that it only runs the update once rather than continuously.
Help greatly appreciated
using UnityEngine;
using System.Collections;
public class RaycastTriangle : MonoBehaviour {
// Use this for initialization
void Start () {
}
void Update() {
RaycastHit hit;
Vector3 up = transform.TransformDirection(Vector3.up);
if (Physics.Raycast(transform.position, up, out hit))
{
if (hit.collider.gameObject.CompareTag("Triangle"))
{
print("Triangle");
}
else if (hit.collider.gameObject.CompareTag("Circle"))
{
print("Square");
}
else if (hit.collider.gameObject.CompareTag("Circle"))
{
print("Circle");
}
else
{
print("No Shape");
}
}
Debug.DrawRay(transform.position, up, Color.green);
}
}