- Home /
unity iphone raycast problem
hi guys,
i'm trying to make a game in iphone using unity3d....i'm getting trouble when i make touch on the gameobjects...
here is my script....
//.cs
public RaycastHit hit;
void Update() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Input.GetMouseButtonDown(0)) { if(Physics.Raycast(ray,out hit,100)) { Debug.Log("hitted object "+hit.transform.gameObject.name);
}
} }
am getting the error as:
NullReferenceException: UnityEngine.Camera.ScreenPointToRay (Vector3 position)
well i have used the same script in my another scene...thats worked perfectly...but now its not working well....in briefly i have attached mesh colliders all of my gameobjects.....
i have a board in my game with mesh collider attached...and lot of coins(like cylinders) in it...i want to touch that coins and wanna to get that coin name....thats it my problem...any one explain what kind of problem i have now.....
thanks.
hello guys i'm in emerge...please can any one help me....i have searched lot in google...but no luck....
Answer by loopyllama · Mar 10, 2011 at 08:20 AM
you probably don't have a camera tagged as "MainCamera" in the scene with the error and you have a camera tagged as "MainCamera" in the scene in which the script works. Just open the scene in which the error occurs, select the camera, and select "MainCamera" in the Tag property.
You can easily test this in script by commenting out your code and adding this line to your Update():
print ("My main camera is: " + Camera.main.name);
My guess is you will get a similar error.
ya....thats awesome....thank you harmless...perfect answer...
Your answer
Follow this Question
Related Questions
Help with DPAD Input Touch For Mobile 0 Answers
iPhone Touch RayCastHit problem 2 Answers
Raycashit Variable make empty/null/clear? 1 Answer
Unity3D 3.X generates a iPhone_target2AppDelegate? Use? 0 Answers
Unity iPhone 2D Left Right movement 0 Answers