Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LethianGames · Mar 20, 2016 at 05:01 PM · cameragameobjectdestroyenemyspawning

My GameObject remains inGame but is destroyed in the editor (no GameObject on left side/in hierarchy)

An enemy is spawned after trigger is activated, he then rushes towards the player and the camera focuses its gaze on it. After destroying everything works fine, except the GameObject (which is deleted in the editor) is still glitching around upon my player...

Also, I'm getting a Refrence error although the camera stuff is working fine :

NullReferenceException: Object reference not set to an instance of an object ForceGaze.SetCam () (at Assets/Scripts/ForceGaze.js:10) ForceGaze.Update () (at Assets/Scripts/ForceGaze.js:19)

And here's my code where I guess something has to be wrong...any ideas? :) All done in Javascript btw.

ForceGaze.js:

 var camLookAt : Transform;
 var cameraUsed : Camera;
 var Haunt : GameObject;
 
 
 function SetCam()
 {
     if(PlayerSpawnTrigger.spawning == true)
     {
         camLookAt.position = GameObject.FindWithTag("Haunt").transform.position;
     }
 }
 
 
 
 function Update()
 {
 
     SetCam();
 
     if (GazeChecker.ForceGaze == true)
     {
         cameraUsed.transform.LookAt (camLookAt);
     }
 
 }
 
 
 

HauntSpawner.js:

 var Player : Transform;
 var spawnSound: AudioClip;
 
 var MinSpawnPos : float = 5;
 var MaxSpawnPos : float = 25;
 var EnemyPrefab : GameObject;
 
 var MinEnemies : int = 1;
 var MaxEnemies : int = 1;
 var HowManyToSpawn : int = 1;
 
 static var functionActivated = false;
 
 
 function Update()
 {
     ///Spawn enemy on Trigger///
     if(PlayerSpawnTrigger.spawning == true && functionActivated == false)
     {
         Spawn();
     }
 }
 
 
 
 function Spawn()
 {
     var dist : float = Vector3.Distance(Player.position,transform.position);
 
     if(PlayerSpawnTrigger.spawning == true)
     {
         GetComponent.<AudioSource>().PlayOneShot(spawnSound);
 
         var position: Vector3 = Vector3(Random.Range(MinSpawnPos, MaxSpawnPos), 3.2006, Random.Range(MinSpawnPos, MaxSpawnPos));
 
         HowManyToSpawn = 1;
 
         for(var i = 0; i < HowManyToSpawn; i++)
         {
             HauntClone = Instantiate (EnemyPrefab,position,Quaternion.identity);
             HauntClone.tag = "Haunt";
         }
 
         functionActivated = true;
 
     }
 }
 

HauntMoving.js:

 var Player : Transform;
 var MoveSpeed = 4;
 var MinDist = 1;
 var MaxDist = 15;
 
 
 function Update()
 
 
 {
     ///Moves toward Player////
 
     transform.LookAt (Player.position);
 
     var dist = Vector3.Distance(transform.position,Player.position);
 
     if(dist <= MaxDist)
     {
         transform.position += transform.forward * MoveSpeed*Time.deltaTime;
     }
 
     if(dist <= MinDist)
         {
             
             Destroy(GameObject.FindWithTag("Haunt"));
             PlayerSpawnTrigger.spawning = false;
 
         }
     if(PlayerSpawnTrigger.LeftTriggerZone == true)
     {
         Destroy(GameObject.FindWithTag("Haunt"));
     }
 
 }
 


Thanks you for any help!

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ali-hatem · Mar 20, 2016 at 05:22 PM 0
Share

// hi again tray :

  function SetCam()
     {
     if(PlayerSpawnTrigger.spawning == true)
          {
              if(GameObject.FindWithTag("Haunt") != null)
              camLookAt.position = GameObject.FindWithTag("Haunt").transform.position;
          }
     }
avatar image LethianGames Ali-hatem · Mar 22, 2016 at 11:18 AM 0
Share

Alright, so the null reference error is gone - thank you very much! But I still have the problem, that my GameObject is deleted in the editor as soon as it reaches my Player (which is totally fine) but it is still in the game (there it does'nt vanish)...

avatar image Ali-hatem LethianGames · Mar 22, 2016 at 11:56 AM 0
Share

genuinely i don't know but tray to delete on of the 2 scenarios that destroy the hunt to know which one of them do the job or both of them & make sure the hunt brefab is taged Hunt to make sure you are not destroying other object.

Show more comments
avatar image LethianGames · Mar 20, 2016 at 05:32 PM 0
Share

Alright, will do so tomorrow and let You know The outcome - thank You very much! :)

avatar image LethianGames LethianGames · Mar 22, 2016 at 05:02 PM 0
Share

The HauntSpawner.js is attached to an empty GameObject in the world. The Prefab has the $$anonymous$$ovement.js attached to it, since it will not move towards the player because of the max Dist variable within the script - thats why I placed it way out of the game world.

But I needed to attach the movement script to the prefab, since the prefab clones will spawn WITHIN that max Dist and therefore move toward the player when triggered...

The problem is: when spawning a clone with the tag "Haunt", suddenly my Prefab spawns at the same location as well (although it does not have the tag "Haunt" and is not instantiated (its there beforehand, way off) after the trigger but teleported... :)

avatar image Ali-hatem LethianGames · Mar 22, 2016 at 05:49 PM 0
Share

i am afraid you have tagged the empty GameObject as Hunt if so un tag it & don't tag the Prefab in script HauntClone.tag = "Haunt"; you can tag it in unity even it as a Prefab just click it in unity & give it a Hunt tag

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

68 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keep GameObject destroyed on returning to the scene 1 Answer

Information about when it is destroyed any GameObject on scene. 0 Answers

Framing multiple objects from a list along y axis only? 0 Answers

Instantiated bullet wont destroy 1 Answer

How to prevent duplicated gameObjects with disabled camera? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges