- Home /
Instantiating prefabs and then moving a gameobject to them
Basically i have a gun that shoots 2 portals, they each have there own portal script attached to them and when a player walks into the trigger it moves them to the other portal
the problem i am having is that they aren't detecting each other correctly after i have instantiated them " 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) portal1.OnTriggerEnter (UnityEngine.Collider player) (at Assets/portal1.js:23) "
Thats the error, i've played around with it a bit and i get that error or similar errors
this is the code im using ( the other portal uses the same code but with everywhere that it says Portal2 it says Portal1
 var Portal2 : GameObject;
 
     function Start ()
     {
 //        Portal2 = GameObject.Find("Portal2");
     }
     
     function Update()
 {
     Portal2 = GameObject.Find("Portal2(Clone)");
 }
     
 function OnTriggerEnter(player:Collider)
 {
     Debug.Log ("player position" +  player.gameObject.transform.position);
     //Debug.Log ( "portal 2 position" + Portal2.gameObject.transform.position);
 
     Debug.Log("trigger is working");
     if (player.gameObject.tag == "Player")
     {    
             Debug.Log("you moved");
             
     player.GameObject.transform.position =  Portal2.GameObject.transform.position;
     }
     
 }
 
 //Destroy (gameObject, 5);
 
Your answer
 
 
             Follow this Question
Related Questions
Creating a reference gameobject of a prefab 0 Answers
How to SetActive(false/true) on an instantiated object, being a clone? 1 Answer
GameObject reference breaks 1 Answer
Destroy and rebuild game objects from lists 1 Answer
How can I replace an object while keeping the references to that object? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                