- Home /
Duplicate Question : http://answers.unity3d.com/questions/750992/cant-pickup-papers-with-script.html
Bug/Error in script CollectPapers
In: if(hit.collider.gameObject.tag == "Paper") It doesnt work , and i dont know why. The object have the Tag Paper and Name Paper
function Update()
{
if (Input.GetKeyDown(KeyCode.E) )
{
Debug.Log("Input is working");
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if ( Physics.Raycast( ray, hit) )
{
Debug.Log("Raycast is working");
if ( hit.collider.gameObject.tag == "Paper" )
{
Debug.Log("Name checking is working");
papers += 1;
audio.PlayClipAtPoint( paperPickup, transform.position );
Destroy(hit.collider.gameObject);
theEnemy.ReduceDistance();
}
}
}
}
The raycast havent direction . I think , but im new and i dont know how do it
Are you getting the 'Raycast is working' output? If so, add:
Debug.Log(hit.collider.name+", "+hit.collider.tag);
If you are not getting the 'Raycast is working' output, then verify that the object has a 3D collider, and that the collider is correctly aligned with the object.
The raycast havent direction . I think , but im new and i dont know how do it
The direction is part of the ray. Rays have an 'origin' and a 'direction'. I see nothing specifically wrong with your code, but check out the two areas I list above.
"The object have the Tag Paper and Name Paper"... and it also has a collider component, right?
Follow this Question
Related Questions
Changing position of a RayCast 1 Answer
Raycast on touch 3 Answers
gameObject tag 2 Answers
How to damage gameobject via raycast 1 Answer