Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Aug 15, 2013 at 10:44 AM by duclaw for the following reason:

the question was answered in the comments section

This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by duclaw · Jul 11, 2013 at 10:23 AM · gameobjecttransformtagsname

adding tag to the player causes issues to the npc

whenever I add a tag to my target it makes the npc accessing the script to start playing a particular animation automatically and it doesn't respond to any other condition in the script, I have tried using target= GameObject.Find("cougar") but it still throws the same error and if I don't add a tag it throws a null reference exception, please i've been battling with this for months now and any help will be appreciated here is the code below

  function Awake()
     {
         myTransform = transform; //cache transform data for easy access/performance
     }
      
     
     function Start()
     {
          target = GameObject.FindWithTag("Player").transform; //target the player 
          target = GetComponent(Transform);
          myTransform = GetComponent(Transform);
     } 
     
     unction strotAway()
     {
        animation["deerStrot"].speed=4;
        animation.CrossFade("deerStrot");
     //rotate to look away from the player
         myTransform.rotation = Quaternion.LookRotation(myTransform.position - target.transform.position);
     // move away from player   
         moveDirection = myTransform.position-target.position;    
         myTransform.position += moveDirection*strotSpeed*Time.deltaTime;
     }
Comment
Add comment · Show 3
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 moonstruck · Jul 11, 2013 at 10:39 AM 2
Share

When strotAway is called?

There are a couple of issues with the code: lines 10-11. The line 10 makes the previous line pointless because you replace the target value with the Transform of your current object, not the player. And line 11 does the same as line 3 in Awake so you can effectively remove it.

avatar image duclaw · Jul 11, 2013 at 05:57 PM 1
Share

@moonstruck you are a life saver and I will never forget your help thanks

avatar image SubatomicHero · Jul 17, 2013 at 07:23 AM 0
Share

@duclaw can you mark @moonstruck's answer as correct please :D

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

17 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

Related Questions

how can i move another gameobject from a single script? 1 Answer

Rotate a GameObject without affecting the direction of motion? 0 Answers

My script doesnt respond what i wrote HELP!!! 0 Answers

Problems with Transform.Find and GameObject.find 1 Answer

How to destroy a transform's parent object. 1 Answer


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