Hey,
I have a script here, and when I drag it on an object called GemPrefab, it gives this error and I don’t understand what’s wrong with it.
It’s used for my adroid tablet, that when I touch it, it plays a sound, destroys the prefab and add 100 points of score.
#pragma strict
var PingGood: AudioClip;
function Update () {
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Began)
{
if (Physics.Raycast (ray, hit, 100))
{
if(hit.collider.gameObject.tag == "GemPrefab")
{
audio.PlayOneShot(PingGood);
Destroy (gameObject);
ScoreBoard.SCORE = (ScoreBoard.SCORE + 100);
}
}
}
}
This is the error: NullReferenceException
UnityEngine.Camera.ScreenPointToRay (Vector3 position) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/UnityEngineCamera.cs:291)
TouchScript.Update () (at Assets/scripts/TouchScript.js:7)
I don’t understand what’s wrong. Hope for your help! Can’t get it right for weeks!