Quantcast
Channel: Questions in topic: "unity3.5"
Viewing all articles
Browse latest Browse all 122

NullReferenceException and he referenced script on this Behaviour

$
0
0
Hello i am new to unity and c#. Not be able to resolve my error. i want to count pumpkin but not able to count. My count value only changes from 0 to 1 only. @kush. Waiting for the response. Thanks Below is my code GolemController using System.Collections; using System.Collections.Generic; using UnityEngine; public class GolemController : MonoBehaviour { private Rigidbody myBody; private float moveForce = 10f; void Awake () { Screen.orientation = ScreenOrientation.LandscapeLeft; myBody = GetComponent(); } // Update is called once per frame void Update () { // for compuetr or desktop float h = Input.GetAxis ("Horizontal"); myBody.velocity = new Vector3 (-h * moveForce, 0f, 0f); // for mobile device //myBody.transform.Translate(Input.acceleration.x, 0 ,0); } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class GolemController : MonoBehaviour { private Rigidbody myBody; private float moveForce = 10f; void Awake () { Screen.orientation = ScreenOrientation.LandscapeLeft; myBody = GetComponent(); } // Update is called once per frame void Update () { // for compuetr or desktop float h = Input.GetAxis ("Horizontal"); myBody.velocity = new Vector3 (-h * moveForce, 0f, 0f); // for mobile device //myBody.transform.Translate(Input.acceleration.x, 0 ,0); } } Spawner using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spawner : MonoBehaviour { public Transform[] spawnPoints; public GameObject pumpkin; void Start () { StartCoroutine (StartSpawning ()); } IEnumerator StartSpawning() { yield return new WaitForSeconds (Random.Range (1f, 3.5f)); Instantiate (pumpkin, spawnPoints [Random.Range (0, spawnPoints.Length)].position, Quaternion.identity); StartCoroutine (StartSpawning ()); } } PumkinScript using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PumkinScript : MonoBehaviour { private int count; public Text countText; void Satrt(){ count = 0; setCountText (); } void FixedUpdate () { if (transform.position.y < -3f) { count = count + 1; setCountText (); Destroy (gameObject); } } void OnCollisionEnter(Collision target) { if (target.gameObject.tag == "Golem") { Destroy (target.gameObject); Time.timeScale = 0f; } } void setCountText() { countText.text = "Count : " + count.ToString (); } } My errors are The referenced script on this Behaviour (Game Object 'Pumkin') is missing! UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion) c__Iterator0:MoveNext() (at Assets/Script/Spawner.cs:16) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) NullReferenceException: Object reference not set to an instance of an object PumkinScript.setCountText () (at Assets/Script/PumkinScript.cs:37) PumkinScript.FixedUpdate () (at Assets/Script/PumkinScript.cs:21)

Viewing all articles
Browse latest Browse all 122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>