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 08:08 AM · camerajavascriptgameobjectfollowclone

How can I get my camera to follow a clone after a certain trigger occurs?

The next issue I've been biting my teeth out on: After trigger occurs, I want my main Player camera to focus its "gaze" on the incoming enemy clone which has spawned. Problem is though, it wont. Is there something I'm missing in my code? How can I address the spawned "enemy(Clone)" properly? All done in Javascript btw.

Any help greatly appreciated!

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

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Ali-hatem · Mar 20, 2016 at 03:31 PM

if this script is attached to the player :

     function SetCam()
      {
          if(PlayerSpawnTrigger.spawning == true)
          {
             // edetid
             camLookAt.position = GameObject.FindWithTag("Haunt").transform.position; 
          }
      }
 
 function Update()
      {
     // you have to call function SetCam()  here to detect enemy each time spawning unless you have other way. 
          function SetCam() 
          if (GazeChecker.ForceGaze == true)
          {
              cameraUsed.transform.LookAt (camLookAt);
          }
      
      }

but what if you have 2 enemies or more let me know

Comment
Add comment · Show 1 · Share
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 LethianGames · Mar 20, 2016 at 03:57 PM 0
Share

Hi, thanks for your reply!

I still keep getting an Exception error:

UnityException: Tag: Haunt is not defined. UnityEngine.GameObject.FindWithTag (System.String tag) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineGameObjectBindings.gen.cs:297) ForceGaze.SetCam () (at Assets/Scripts/ForceGaze.js:9) ForceGaze.Update () (at Assets/Scripts/ForceGaze.js:18)

After your edits, my new code looks like this now:

 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);
     }
 
 }
 
 
 

I did attach the "Haunt"-Prefab in the editor, but still i am getting this error...not sure where I am supposed to define it then...

And yes, i only need 1 enemy ;)

avatar image
0

Answer by LethianGames · Mar 20, 2016 at 04:11 PM

Ok, so i found the problem:

When heading to Edit -> Project Settings -> Tags & Layers, i added a Tag called "Haunt". Then i went into my Haunt-Prefab and gave him the tag "Haunt".

Now the camera focuses on him (he is somewhere waaaaay off in the game world) but i want the camera to focus on the spawned Haunt(Clone) instead...any idea how to approach this?

Because I cant attach the tag to the Haunt(Clone)-Object alone, because it has not spawned yet...

Comment
Add comment · Show 4 · Share
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 04:34 PM 0
Share

sorry i don't get what you mean by Haunt(Clone) isn't it the same Haunt-Prefab

avatar image LethianGames · Mar 20, 2016 at 04:40 PM 0
Share

Yes, exactly - it is the same prefab. $$anonymous$$y Spawner script will instantiate a "Haunt(Clone)". And i need to put a tag on ONLY that clone. The code line looks like this:

 for(var i = 0; i < How$$anonymous$$anyToSpawn; i++)
         {
             Instantiate (EnemyPrefab,position,Quaternion.identity);
         }

is there a way to assign a created tag ONLY to this clone?

avatar image Ali-hatem LethianGames · Mar 20, 2016 at 06:12 PM 0
Share

but you already said

i went into my Haunt-Prefab and gave him the tag "Haunt".

so where is the problem
avatar image LethianGames Ali-hatem · Mar 22, 2016 at 11:23 AM 0
Share

I added your code bit from this thread: http://answers.unity3d.com/questions/1158125/my-gameobject-remains-ingame-but-is-destroyed-in-t.html

And everything works fine now except of the problem described in my comment within the other thread. Thank you very much for your help :)

I'll close this thread now ;)

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

79 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How get position from a game object? 5 Answers

How to Parent a Camera to the Head Bone with No Camera Shake? 0 Answers

How to make a GUI bar that counts items collected 0 Answers

How can I make the Player be destroyed when I touch the end of the camera? 1 Answer

How do you disallow an angle from going to a certain range while rotating? 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