Hi to all… I imported a project that i’ve made with unity 3 and there wasn’t errors, when I import the project in Unity 5 this script give me this error: Object reference not set to an instance of an object… Why in Unity 3 I don’t have this problem?
The line where ther’s the error is ray = Camera.main.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
Hope someone can help me.
Here the full script
private var decrement : float;
private var toggle : boolean;
private var ray : Ray;
private var hitInfo : RaycastHit;
var Audio : AudioClip;
function Start()
{
decrement = transform.localScale.y / 1.3f; //modificare questo valore per ridurre l'altezza.
}
function OnMouseDown()
{
if(!enabled) return;
ray = Camera.main.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
if(Physics.Raycast(ray, hitInfo))
{
if(hitInfo.transform.gameObject == gameObject)
{
if(Input.GetMouseButton)
{
if(!toggle)
{
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y - decrement, transform.localScale.z);
transform.position.y += decrement / 2;
toggle = true;
GetComponent.<AudioSource>().clip = Audio;
GetComponent.<AudioSource>().Play();
}
else
{
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y + decrement, transform.localScale.z);
transform.position.y -= decrement / 2;
toggle = false;
GetComponent.<AudioSource>().clip = Audio;
GetComponent.<AudioSource>().Play();
}
}
}
}
}