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 lazlo · Jan 07, 2013 at 10:33 AM · animationtutorial

Unity 4 animation.Play problem!plz help

hey im new at scripting and i watch a tut series! The tut series is from unity 3.5.6 and i have unity 4.0 and i discoverd a problem with scripting i made some other script withis function(animation.Play) but none of them seems to work.I don know how can I do this script working so plz help me!!

Here is the script:

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class PlayerController : MonoBehaviour { public CharacterController CharCont; public CharacterMotor CharMotor;

 //Holders fo Weapons
 public Transform WalkAnimationHolder;
 public Transform JumpAnimationHolder;
 public Transform SwayHolder;
 public Transform RecoilHolder;
 public Transform RecoilHolderCamera;
 
 public WalkingState walkingstate = WalkingState.Idle;
 
 public float VelocityMagnitude;
 
 public float WalkSpeed;
 public float RunSpeed;
 
 public bool WasStanding;
 
 public WeaponInfo CurrentWeapon;
 public List WeaponList = new List();
 
 public Vector3 CurrentRecoil1;
 public Vector3 CurrentRecoil2;
 public Vector3 CurrentRecoil3;
 public Vector3 CurrentRecoil4;
 
 private float shoottime = 0;
 
 void Start()
 {
     CurrentWeapon = WeaponList[0];
 }
 
 public void Update()
 {
     ShootController();
 }
 
 public void FixedUpdate()
 {
     AnimationController();
     SwayController();
     SpeedController();
     RecoilController();
     VelocityMagnitude = CharCont.velocity.magnitude;
 }
 
 public void SpeedController()
 {
     if((Input.GetAxis ("Horizontal")!=0 || Input.GetAxis ("Vertical")!=0) &&   VelocityMagnitude>0)
     {
         if(Input.GetButton("Run"))
         {
             walkingstate = WalkingState.Running;
             CharMotor.movement.maxForwardSpeed = RunSpeed;
             CharMotor.movement.maxSidewaysSpeed = RunSpeed;
             CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2;
         }
         else
         {
             walkingstate = WalkingState.Walking;
             CharMotor.movement.maxForwardSpeed = WalkSpeed;
             CharMotor.movement.maxSidewaysSpeed = WalkSpeed;
             CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2;
         }
     }
     else
     {
         walkingstate = WalkingState.Idle;
     }
 }
 
 public void AnimationController()
 {
     
     if(WasStanding && !CharCont.isGrounded)
     {
         WasStanding = false;
         JumpAnimationHolder.animation.Play("TestJump");
     }
     else if(!WasStanding && CharCont.isGrounded)
     {
         WasStanding = true;
         JumpAnimationHolder.animation.Play("TestLand");
     }
     
     
     
     if( walkingstate == WalkingState.Running)
     {
         WalkAnimationHolder.animation["M4_Running"].speed = VelocityMagnitude / RunSpeed * 1.2f;
         WalkAnimationHolder.animation.CrossFade("M4_Running", 0.2f);
     }
     else if( walkingstate == WalkingState.Walking)
     {
         WalkAnimationHolder.animation["M4_Running"].speed = VelocityMagnitude / WalkSpeed * 1.2f;
         WalkAnimationHolder.animation.CrossFade("M4_Walking", 0.2f);
     }
     else
     {
         WalkAnimationHolder.animation.CrossFade("M4_Idle", 0.2f);
     }
         
 }
 
 public void SwayController()
 {
     
 }
 
 public void ShootController()
 {
     if(Input.GetButton("Fire1"))
     {
         if (shoottime <= Time.time)
         {
             shoottime = Time.time + CurrentWeapon.firerate;
             CurrentRecoil1 += new  Vector3(CurrentWeapon.RecoilRotation.x, Random.Range (- CurrentWeapon.RecoilRotation.y,CurrentWeapon.RecoilRotation.y));
             CurrentRecoil3 += new Vector3(Random.Range (- CurrentWeapon.RecoilKickback.x,CurrentWeapon.RecoilKickback.x),Random.Range (-       CurrentWeapon.RecoilKickback.y,CurrentWeapon.RecoilKickback.y),CurrentWeapon.RecoilKickback  .z);
         }
     }
 }
 
 public void RecoilController()
 {
     CurrentRecoil1 = Vector3.Lerp(CurrentRecoil1 ,Vector3.zero ,0.1f);
     CurrentRecoil2 = Vector3.Lerp(CurrentRecoil2 ,CurrentRecoil1 ,0.2f);
     CurrentRecoil3 = Vector3.Lerp(CurrentRecoil3 ,Vector3.zero ,0.1f);
     CurrentRecoil4 = Vector3.Lerp(CurrentRecoil4 ,CurrentRecoil2 ,0.2f);
     
     RecoilHolder.localEulerAngles = CurrentRecoil2;
     RecoilHolder.localPosition = CurrentRecoil4;
     
     RecoilHolderCamera.localEulerAngles = CurrentRecoil2 / 1.3f;
 }

}

public enum WalkingState { Idle, Walking, Running }

[System.Serializable] public class WeaponInfo { public string name = "Weapon"; public float firerate = 0.1f;

 public Transform WeaponTransform;
 
 public Vector3 RecoilRotation;
 public Vector3 RecoilKickback;

}

plz plz plz plz someone plz help me

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 lazlo · Jan 07, 2013 at 11:55 AM 0
Share

plz someone help me!

avatar image markfm · Jan 07, 2013 at 06:55 PM 0
Share

For a beginner to scripting you are really going into the deep end. You have not included any information to allows us to help you.

What is this attached? What do you mean does not work? what did you connect it to? Did you write this script yourself? Do you understand it?

avatar image lazlo · Jan 07, 2013 at 07:16 PM 0
Share

i dont made the script but i fully understand it! and when i say does not work i mean that the function animation.Play isnt working in unity 4 to be more accurate i mean that when i walk the animation isnt playing and i tryed this function(animation.Play) to other scripts but it still doesnt playing the animation however in Unity 3.5.6 it worked fine!!!

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Can I make animations snap to a frame? 1 Answer

How to resume animation from last frame 2 Answers

Animation not occuring instant,Survival Shooter Walking animation not instant... 1 Answer

Good Tutorial from 3DsMax until Unity3d 1 Answer

BlendTree - turn animation right/left get stuck 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