Good afternoon, all right? I’m having the following problem… I have a code that have attached to the player, which identifies when the player clicks the object with the tag “Box” when it is at a certain distance… The code was working perfectly in an earlier version of Unity, however after I updated to latest version, the code does not work anymore… Below is my code:
#pragma Strict
var box1 : boolean = false;
function Start () {
}
function Update () {
var fwd = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, fwd, Color.green);
if((Physics.Raycast(transform.position, fwd, 1.7)) && caixa == box1)
{
print("You clicked on the box!");
}
}
function OnMouseDown (hit : GameObject) {
if(hit.tag == "Box")
{
box1 = true;
}
}
I did some testing and found that the problem is in the OnMouseDown function, but found it odd, because it worked perfectly so far little. Can someone help me? If there is another better way to do the same thing, I accept suggestions, because I’m still new to Unity! Thank you!! (: