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…
i have posted the same question in answers.unity3d.com…http://answers.unity3d.com/questions/45397/unity-iphone-raycast-problem