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 /
avatar image
0
Question by javanoob · Apr 02, 2013 at 12:50 PM · tagwaypointfindgameobjectwithtag

Waypoint Arrow not pointing at tagged object ?

Hi ,strange problem here as usual lol ,I am using a simple piece of code which is attached to a cone mesh which is a child of the main camera and I want it to point at my tagged waypoints in turn ,so I start simple and use waypoint 1 (tagged as "1") and the arrow rotates but actually points at the center of my terrain and not the tagged waypoint ? (I have checked and the terrain is not tagged at all) ? heres the JS (pragma strict) . Any clue ?

 #pragma strict
 function Update () {
      
     var object = GameObject.FindGameObjectWithTag("1");
     var target = object.transform;
     transform.LookAt(target , Vector3(0,0,1));
     transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
 
 }


lol fixed ,I had a DUH moment after I posted ,the Original code was wrong the line

transform.LookAt(target , Vector3(0,0,1));

should be

transform.LookAt(target);

Hope this helps people with arrow pointer problems lol :)

Comment
Add comment · Show 1
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 javanoob · Apr 02, 2013 at 01:49 PM 0
Share

As im here already ^^ I am trying to read the value of ckp from a script called Checkpoint01 so I know where the arrow should point but I guess I have the example wrong .Any ideas please ,I should point out that the scripts are on two different objects :()

 #pragma strict
 function Update () {
     
    // Find the OtherScript which is attached to any game object in the scene.
     var other : Checkpoint01 = FindObjectOfType(ckp);
     if (ckp==1) var object = GameObject.FindGameObjectWithTag("1");
     if (ckp==2) var object = GameObject.FindGameObjectWithTag("2");
     
     var target = object.transform;
     
     transform.LookAt(target);
     
     transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
 
 }

1 Reply

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

Answer by robertbu · Apr 02, 2013 at 03:21 PM

FindObjectOfType() is very slow and should not be done every frame. Typically you would give the game object with the script attached a name know name and use GameObject.Find() to get the object in start (or drag and drop into a public variable). I also don't see where ckp is declared or set in this code, so I cannot check how that is being used. And you execute code even if object has not been initialized. Here is your code with a couple of mods:

 #pragma strict
 
 var other : CheckPoint01;
 
 function Start () {
      other = GameObject.Find("Other_Name").GetComponent(CheckPoint01);
 }
 
 function Update () {
     var object : GameObject = null;
     
     if (other.ckp==1) 
         object = GameObject.FindGameObjectWithTag("1");
     if (other.ckp==2) 
         object = GameObject.FindGameObjectWithTag("2");
      
      if (object != null) {
         var target = object.transform;
  
         transform.LookAt(target);
          transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
          }
 }

I assume the transform.rotation is because the natural rotation of the arrow is not towards positive 'z'?

Comment
Add comment · Show 16 · 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 javanoob · Apr 02, 2013 at 05:14 PM 0
Share

var ckp =0;

this is setup in CheckPoint01.js

ps what do I put in other_name field ,sorry im a bit lost still lol

I get this error ?

Assets/direx.js(3,13): BCE0018: The name 'CheckPoint01' does not denote a valid type ('not found').

Is it because the checkpoint script is not on the same object ? and can I get a value from a script on a different object ?

avatar image robertbu · Apr 02, 2013 at 05:20 PM 0
Share

I edited the code above to access ckp in other. "Other_Name" will be the name of the game object that the CheckPoint01 script is attached to. As for the error, the type and the file name must match exactly. That is "Checkpoint01.js" is not "CheckPoint01.js" If the names match, then the error should go away.

avatar image robertbu · Apr 02, 2013 at 05:38 PM 0
Share

As I said above, the names must match exactly. So you can either change the name of the script to "CheckPoint01", or you can change the type used above to "Checkpoint01". Even a capital letter difference is enough to generate the error.

avatar image javanoob · Apr 02, 2013 at 05:39 PM 0
Share

Thanks lol silly mistake :p

avatar image javanoob · Apr 02, 2013 at 08:23 PM 0
Share

Still problems lol heres my ckp value in the Checkpoint01 script

  // Checkpoint01.js


     if (hit.gameObject.name == "Cube1"){
                   
                ckp=ckp+1;
             GameObject.Find("Cube2").transform.Translate(0, -5000, 0);
             GameObject.Find("Cube1").transform.Translate(0, 5000, 0);
         }
     
      else if (hit.gameObject.name == "Cube2"){
                  
                ckp=ckp+1;
                GameObject.Find("Racetext").renderer.enabled = false;
             GameObject.Find("Cube3").transform.Translate(0, -5000, 0);
             GameObject.Find("Cube2").transform.Translate(0, 5000, 0);
     }
     
     else if (hit.gameObject.name == "Cube3"){
            
            ckp=ckp+1;      
             GameObject.Find("Cube4").transform.Translate(0, -5000, 0);
             GameObject.Find("Cube3").transform.Translate(0, 5000, 0);
           
           }
 
 
 I just need to read the value of ckp from the above script into this one below

// direx.js

 #pragma strict
    
   
  
 function Update () {
  if (ckp==1) var object1 = GameObject.Find("Cube2");
         var target1 = object1.transform;
           transform.LookAt(target1);
               transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
 
  if (ckp==2) var object2 = GameObject.Find("Cube3");
         var target2 = object2.transform;
           transform.LookAt(target2);
               transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
 
 //   etc  till 
 
  if (ckp==10) var object3 = GameObject.Find("Cube1");
         var target3 = object3.transform;
           transform.LookAt(target3);
               transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
 
 
 }



Show more comments

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

11 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

Related Questions

FindGameObjectsWithTag works only to first tagged 1 Answer

Swapping a tag for string not working, replacing a tag with a public string, help. 1 Answer

Using tags to move player toward objects 1 Answer

Get a total count of gameobjects with the same tag and change level if score reaches max score! 0 Answers

How to move a gameobject when it lands on a tag, to another tag? 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