Idle Run Jump script addition help.

Hi

Trying to get the animator controller to work and have added a roar animation for my monster. The animation is in the base layer and taps off the idle animation. I am using the Idle Run Jump script and have added a bool and tried to edit the script so it works but it doesnt. Also the Hi animation loops once activated, it just keeps going and going when it should be a one time animation. Is there a way to stop that?
Here is the script where I tried to add Roar to Fire3. Any help appreciated.

using UnityEngine;
using System.Collections;

public class IdleRunJump : MonoBehaviour {


	protected Animator animator;
	public float DirectionDampTime = .25f;
	public bool ApplyGravity = true; 

	// Use this for initialization
	void Start () 
	{
		animator = GetComponent<Animator>();
		
		if(animator.layerCount >= 2)
			animator.SetLayerWeight(1, 1);
	}
		
	// Update is called once per frame
	void Update () 
	{

		if (animator)
		{
			AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);			

			if (stateInfo.IsName("Base Layer.Run"))
			{
				if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);                
            }
			else
			{
				animator.SetBool("Jump", false);                
            }

			if(Input.GetButtonDown("Fire2")  animator.layerCount >= 2)
			{
				animator.SetBool("Hi", !animator.GetBool("Hi"));
			}
			
		if(Input.GetButtonDown("Fire3"))
			{
				animator.SetBool("Roar", !animator.GetBool("Roar"));
			}
      		float h = Input.GetAxis("Horizontal");
        	float v = Input.GetAxis("Vertical");
			
			animator.SetFloat("Speed", h*h+v*v);
            animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);	
		}   		  
	}
}

I dont have much time right now to look at all of this, but for your Hi animation, locate it in your assets window and check to see if in the inspector if looping is enabled, if so, set it to once instead, that should fix it

Thanks for your reply Mike L. You were right the animation was set to loop. :slight_smile:

it seems to me like you should try if(Input.GetButtonDown("Fire3") animator.layerCount >= 5) instead of if(Input.GetButtonDown("Fire3")) just a quick guess, not completely sure what is all goin on, are you getting any errors or something?

Hi Mike L

With your changes I receive no error at all. I connected up the Roar animation with the idle and assigned a Bool that has a true parameter like the Hi animation on the out transition. It isnt working yet though. This is what I put.

using UnityEngine;
using System.Collections;

public class WolfAnimation : MonoBehaviour {


	protected Animator animator;
	public float DirectionDampTime = .25f;
	public bool ApplyGravity = true; 

	// Use this for initialization
	void Start () 
	{
		animator = GetComponent<Animator>();
		
		if(animator.layerCount >= 2)
			animator.SetLayerWeight(1, 1);
	}
		
	// Update is called once per frame
	void Update () 
	{

		if (animator)
		{
			AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);			

			if (stateInfo.IsName("Base Layer.Run"))
			{
				if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);                
            }
			else
			{
				animator.SetBool("Jump", false);                
            }

			if(Input.GetButtonDown("Fire2")  animator.layerCount >= 2)
			{
				animator.SetBool("Hi", !animator.GetBool("Hi"));
			}
			if(Input.GetButtonDown("Fire3")  animator.layerCount >= 5)
			{
				animator.SetBool("Roar", !animator.GetBool("Roar"));
			}
		
      		float h = Input.GetAxis("Horizontal");
        	float v = Input.GetAxis("Vertical");
			
			animator.SetFloat("Speed", h*h+v*v);
            animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);	
		}   		  
	}
}

I decided to try and dial everything back to basics and found this code on youtube:

var WolfAnimation : Animator;

function Update()
	{
	
		if (Input.GetKeyUp ("1"))
			WolfAnimation.SetBool("Roar", true);
			
		if (Input.GetKeyUp ("2"))
			WolfAnimation.SetBool("Roar", false:
}

I named the script WolfAnimation and there are only 2 states: Idle and Roar so everything is stripped back to a minimum. The above script gives me:
Assets/Scripts/WolfAnimation.cs(2,19): error CS8025: Parsing error
On the console.
I think this is the part of the error log that targets this:
Assets/Scripts/WolfAnimation.cs

-----CompilerOutput:-stdout–exitcode: 1–compilationhadfailure: True–outfile: Temp/Assembly-CSharp.dll

Compilation failed: 1 error(s), 0 warnings

-----CompilerOutput:-stderr----------

Assets/Scripts/WolfAnimation.cs(2,19): error CS8025: Parsing error

-----EndCompilerOutput---------------

  • Finished compile Library/ScriptAssemblies/Assembly-CSharp.dll
    Assets/Scripts/WolfAnimation.cs(2,19): error CS8025: Parsing error

(Filename: Assets/Scripts/WolfAnimation.cs Line: 2)

Refresh, detecting if any assets need to be imported or removed … 0.021242 seconds (Nothing changed)

I am trying to find a way to get the animator to work without having the slightest idea how. Google is helpful up to a point. I also tried a combination of the first script and the second but got a 1 key not initialized error while adding the key in the project settings/ input didnt help.

Thank you very much for your help so far it is much appreciated.

Is this the whole script? It doesnt appear that there is anything on line 2, also, the first script your using is in c#, the second is in java script, and you appear to have saved the js code as a c# file, this wont work out very well since the languages have 2 very different syntaxes…

Thanks Mike L
Took the space out on line 2 and saved as a JS on the second one and it works great.

Cheers

no problem, Happy to help