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 felixfors · Jun 23, 2013 at 04:11 AM · animationreverse

Animation reverse

Hey there!. Im having problem with my script. what the script does is that it displays a icon when you are aiming on the " door " and that works just fine and opening also. the thing Im trying to add to the script that gives me problem is animation reverse for closing the door. it gives me a error at line 41 saying that " = " is incorrect. isnt that how it suppose to be ?

 function Update()
 {
        var hit : RaycastHit;
  
        //check if we're colliding
        if(Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
        { 
           showSymbol = true;
  
           //with a door
           if(hit.collider.gameObject.tag == "doorl")
           {
            
               if(Input.GetKeyDown("e"))
               {
                  //open the door!
                  hit.collider.gameObject.animation.Play("doorleft");
                 
                }
                 }
                 else
                 {
 
                    {   
                  hit.collider.gameObject.animation.Play("doorleft").speed=-1f;
                  }
                 }
                  
               
                           
  
  
           //Copy and paste the code above and rename the door animation and that's it! You now have another door in your game!
  
        }
        else
        {
          showSymbol = false;
        }
      }
    }
   }
  }

 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by deltamish · Jun 23, 2013 at 06:15 AM

Hi the problem is very simple all you have to do is change from

CHANGE FROM

 {
 hit.collider.gameObject.animation.Play("doorleft").speed=-1f;
 }

the reason this line doesnt work is because animation.Play(); is call only function

CHANGE TO

     {
 hit.collider.gameObject.animation["doorleft"].time = hit.collider.gameObject.animation["doorleft"].length;
     hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
     hit.collider.gameObject.animation.Play("doorleft");
     }



Your Script Rewritten

 var dooropen:boolean = false;
 function Update(){
 var hit:RaycastHit;
 
 if(Physics.Raycast(transform.position, transform.forward,hit, rayCastLength)){
 
  showSymbol = true;
 
 if(hit.collider.gameObject.tag == "doorl"){
 
 if(Input.GetKeyDown(KeyCode.E)){
 dooropen = true;
  hit.collider.gameObject.animation.Play("doorleft");
      
     }else{
 if(dooropen){
          hit.collider.gameObject.animation["doorleft"].time = hit.collider.gameObject.animation["doorleft"].length;
         hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
         hit.collider.gameObject.animation.Play("doorleft");   
 dooropen = false;
     }

  
      }
 
    }else{
  showSymbol = false;
   }
  }
 }
Comment
Add comment · Show 8 · 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 felixfors · Jun 23, 2013 at 12:26 PM 0
Share

Thanks Deltamish I tried it out and it still gives me the same error :( it says ( expecting token : ,found "=" ) on line 42. I know that it means that I need to change = symbol to : but that wont work eather I have also looked in to other reverse animaition scripts and mostly all of them uses " = ", why cant I ? : (

avatar image deltamish · Jun 27, 2013 at 04:14 PM 0
Share

Hi @felixfors Sorry for the late reply i dont know why you are getting this error Are you sure you typed the codes correctly and please post the full error and the script

avatar image felixfors · Jun 28, 2013 at 04:02 PM 0
Share

Hey @deltamish Im still struggeling with this problem and Im glad for all posible help I can get. Full script:

function Update() { var hit : RaycastHit;

    //check if we're colliding
    if(Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
    { 
       showSymbol = true;
 
       //with a door
       if(hit.collider.gameObject.tag == "doorl")
       {
 
           if(Input.Get$$anonymous$$eyDown("e"))
           {
              //open the door!
              hit.collider.gameObject.animation.Play("doorleft");
 
            }
             }
             else
             {
 
                {   
               hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
               hit.collider.gameObject.animation.Play("doorleft");
              }
 
 
 
 
       //Copy and paste the code above and rename the door animation and that's it! You now have another door in your game!
 
    }
    else
    {
      showSymbol = false;
    }
  }

} } }

Error: BCE0044: expecting :, found "=". at line 25.

avatar image deltamish · Jun 28, 2013 at 04:14 PM 0
Share

why are there two flower brackets here

  else
 {
  
 {///This one here shouldnt belong i think
 hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
 hit.collider.gameObject.animation.Play("doorleft");
 }

and here

  if(Input.Get$$anonymous$$eyDown("e"))
 {
 //open the door!
 hit.collider.gameObject.animation.Play("doorleft");
  
 }
 }
 else
 {

I have rewriiten your complete script try it

avatar image felixfors · Jun 28, 2013 at 06:52 PM 0
Share

Hey thanks! it seams to have changed something to the better, but It still not 100% working, the animation plays reversed now but when ever I walk up close to the door without pressing any key to trigger the animation it just goes off playing by itself but like a ping pong effect" close and open" repeatedly tils I step away from the door. why? I want the animation only to be played when $$anonymous$$ey E is pushed down :(

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

16 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

Related Questions

Flip back a frame 1 Answer

How to stop a FBX animation mid-way and then reverse it from that point? 1 Answer

Help making an animated door (c#) 2 Answers

Play animation backwards 1 Answer

[Solved] Reverse animation 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