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 therealjackwalden · Apr 25, 2012 at 03:00 PM · javascriptcompile-error

Unknown identifier

Hi there, I'm trying to make an object (the object is named "dodecahedron") animate by a player coming into a close proximity of said object - I was given this script earlier on.

 var target : Transform;
 var detectRange: float = 30;
 
 function Update() {
     var tgtDirection = target.position - transform.position; 
  
     var tgtDistance = tgtDirection.magnitude;
     if (tgtDistance <= detectRange) {
         dodecahedron.animation.Play("Animation");
     }
 }

HOWEVER when I try and input the code I get this message: "Assets/Proximity.js(8,1): BCE0005: Unknown identifier: 'dodecahedron'."

What am i doing wrong?

Comment
Add comment · Show 2
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 ByteSheep · Apr 25, 2012 at 03:42 PM 0
Share

The error appears because you haven't set "dodecahedron" as a variable in the script.. You could try this :)

 var dodecahedron : GameObject;
 var target : Transform; 
 var detectRange: float = 30;
 
 function Start() {
 
 dodecahedron = GameObject.Find("dodecahedron");
 
 }
 
 
 function Update() {
 
 var tgtDirection = target.position - transform.position;
 
 var tgtDistance = tgtDirection.magnitude;
 
   if (tgtDistance <= detectRange) 
   {
   dodecahedron.animation.Play("Animation"); 
   }
 
 }
avatar image therealjackwalden · Apr 26, 2012 at 10:20 AM 0
Share

I've attached that script to the shape - but it just seems to play the animation on a loop. In the inspector I can see something called 'detect range' I've noticed that when i put the value below 0 it doesnt animate - am i anywhere near where i want to be?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by venkspower · Apr 26, 2012 at 10:25 AM

That is because you have never created a "dodecahedron" GameObject in your script.

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

Answer by fafase · Apr 26, 2012 at 11:05 AM

I think you need to change your approach. You have this dodecahedron object right?

So attach to him a script like this

 var player:GameObject;
 var distance:int = 30;
 var animNotPlayed:boolean;
 
 function Start(){
    player = GameObject.Find("Player");  // Find the player
    animNotPlayed=true;
 }

 function Update(){
 if(animNotPlayed){
     // Here I changed player.position to player.transform.position.
    if(Vector3.Distance(player.transform.position,transform.position)<distance){ // Check distance
       animation.Play("Animation");     //Play animation
       animNotPlayed=false;
 }}}
Comment
Add comment · Show 3 · 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 fafase · Apr 26, 2012 at 11:12 AM 0
Share

as a side note, the animNotPlayed is true as long as you hav not played(obviously) once you reach the distance, the anim is played and the bool turns to false, so that the distance is not checked anymore and the animation is not played again.

avatar image therealjackwalden · Apr 26, 2012 at 11:16 AM 0
Share

Im getting this error message when attaching the code you provided "Assets/dodec.js(5,28): BCE0022: Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Transform'."

I'm a complete unity newbie so i only have a very, very basic grasp of what to do

avatar image fafase · Apr 26, 2012 at 11:20 AM 0
Share

I was expecting that actually. this is because the player is a gameobejct and player is of type Transform. I edit quickly.

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

6 People are following this question.

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

Related Questions

UnityEngine.GameObject Error 1 Answer

How do I make my character "throw" and "catch" an object? 1 Answer

How to fire buttons events(down,up) at the same time? 0 Answers

Text clearing issue- game breaking 1 Answer

Hide the ImageTraget in Real world 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