- Home /
Object Refrence Not Set To An Instance Of An Object?
Im Trying To make a minecraft type Terrain Generation Script and it gave me this error :
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) Chunk.Generate () (at Assets/Script/Chunk.js:20) Chunk.Start () (at Assets/Script/Chunk.js:7)
heres my script:
var cubes : GameObject; var spawnInterval = 3.0; var heightScale = 5.0;
 function Start()
 {
 Generate();
 }
 public function PerlinNoise(x : float, y : float) : float
 {
 var noise : float = Mathf.PerlinNoise( x / heightScale, y / heightScale);
 return noise * heightScale;;
 }
 function Generate()
 {
     for (var y = -4; y < 5; ++y)
     for (var x = -4; x < 5; ++x)
     {
     var Cube : GameObject = Instantiate(cubes);
     Cube.transform.position = Generate.transform.position + Vector3(x,PerlinNoise(x,y),y);
     }
 }
Did you remember to drag in the cubes game object in the inspector?
What line is the error? And shouldn't that "Generator..." in line 16 be "`this.transform.position`" ins$$anonymous$$d?
Answer by lighting · Jul 02, 2013 at 02:50 PM
I think that above error indicates that getter doesn't work: what is Generate in your code ? Do you have it as public GameObject defined somewhere else ? Or it's mistake, because your method has name "Generate".
Answer by bonamoogy · Dec 09, 2018 at 11:10 PM
How i solved this? nullrefrenceExcepton = Object refrence not set to instance object
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CrossHair : MonoBehaviour {
 [SerializeField] Texture2D crossHairImg;
 [SerializeField] int size;
 [SerializeField] float maxAngle;
 [SerializeField] float minAngle;
 float lookHeight;
 public void LookHeight(float value)
 {
     lookHeight += value;
     if (lookHeight > maxAngle || lookHeight < minAngle)
         lookHeight -= value;
 }
 private void OnGUI()
 {
     Vector3 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
     screenPosition.y = Screen.height - screenPosition.y;
     GUI.DrawTexture(new Rect(screenPosition.x, screenPosition.y - lookHeight, size, size), crossHairImg);
 }
}
Your answer
 
 
             Follow this Question
Related Questions
This script really makes my game lag! 1 Answer
Minecraft (Cube) Terrain 1 Answer
Voxel based Terrain generation. Pointers please. 2 Answers
How do I make a minecraft like terrain? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                