- Home /
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
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?
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!!!
Your answer
