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 Kinggadino12 · Jan 31, 2014 at 02:58 AM · animationjavascriptmultiple

Multiple Animations for the Same GameObject

I am writing my own, more advanced FPS controller and I have come across a problem with animating. I try to create multiple animations in my FPS Controller GameObject but it says, "Can't add the same object multiple times!". This is really frustrating me because I want to have both a running and a walking animation. Heres my FPS code so far, var rigidBody : Rigidbody; var fpsController : Transform; var fpsGameObject : GameObject;

 var fpsCamera : Transform; 
 var bobHeadRunningAnimation : Animation;
 var bobHeadWalkingAnimation : Animation;
 
 var jumpVelocity : float;
 
 var forwardWalkVel : float; 
 var sideWalkVel : float;
 var backWalkVel : float;
 var runVel : float;

 private var isCrouching : boolean = false;
 private var beforeCrouchHeight : float = 0;

 function Update () {
     if (Input.GetKeyDown(KeyCode.Space))
         prepareJump();

     if (Input.GetKeyUp(KeyCode.Space))
         jump();

     if (Input.GetKey(KeyCode.W)) {
         fpsController.Translate(Vector3.forward * forwardWalkVel * Time.deltaTime);
         bobHead(false);
     }

     if (Input.GetKey(KeyCode.A)) {
         fpsController.Translate(Vector3.left * sideWalkVel * Time.deltaTime);
         bobHead(false);
     }

     if (Input.GetKey(KeyCode.S)) {
         fpsController.Translate(Vector3.back * backWalkVel * Time.deltaTime);
         bobHead(false);
     }

     if (Input.GetKey(KeyCode.D)) {
         fpsController.Translate(Vector3.right * sideWalkVel * Time.deltaTime);
         bobHead(false);
     }

     if (Input.GetKeyDown(KeyCode.C)) {
         if (isCrouching == false) {
             beforeCrouchHeight = fpsController.position.y; //Save Before Crouch Height
             fpsGameObject.transform.localScale = new Vector3(1, 0.52, 1); //0.5 wouldn't work!
             isCrouching = true;
         }
         else if (isCrouching == true) {
             fpsGameObject.transform.localScale = new Vector3(1, 1, 1);
             fpsController.position.y = beforeCrouchHeight; //Reset Height
             beforeCrouchHeight = 0; //Reset Value
             isCrouching = false;
         }
     }

     if (Input.GetKey(KeyCode.LeftShift)) {
         fpsController.Translate(Vector3.forward * runVel * Time.deltaTime);
         bobHead(true);
         if (Input.GetKeyUp(KeyCode.LeftShift))
             bobHeadRunningAnimation.Stop();
     }
 }

 function prepareJump() {
     fpsCamera.Translate(Vector3.down * 0.1);
     forwardWalkVel /= 2;
     sideWalkVel /= 2;
     backWalkVel /= 2;
 }

 function jump() {
     fpsCamera.Translate(Vector3.up * 0.1);
     rigidBody.AddRelativeForce(0, jumpVelocity, 0);
     forwardWalkVel *= 2;
     sideWalkVel *= 2;
     backWalkVel *= 2;
 }

 function bobHead(isRunning : boolean) {
     if (isRunning == true)
         bobHeadRunningAnimation.Play();
     else
             //Cannot do anything until I have another animation
 }


Here is the screen shot of my inspector: alt text

Here is a screenshot of the error: alt text

scrsht.png (39.7 kB)
srcsht2.png (10.4 kB)
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
0

Answer by Swordfish12 · Jan 30, 2017 at 08:06 AM

Change the name

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 ASPePeX · Jan 30, 2017 at 08:33 AM

The exact error message is important, it says component not object! You can indeed only add one Animation component but it can contain multiple animations.

The first image should explain everything: https://docs.unity3d.com/Manual/class-Animation.html

Edit: well, I didn't see this question was necroed from 2014 ...

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

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

20 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

Related Questions

Problem with script. (Sorry for huge code) 1 Answer

String.Split() Function Issues 1 Answer

Talking Code 2 Answers

In Game Animation 2 Answers

character lagging in air when jumped 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