Question is off-topic or not relevant
Jumping and animation script error.
Hi guys,
I am trying to write a script, so when my character jumps the jumping animation play. But for some reason it doesnt seem to be working.
using UnityEngine;
using System.Collections;
public class jumping : MonoBehaviour {
public bool grounded = true;
public float jumpPower = 1;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if(!grounded && rigidbody2D.velocity.y == 0) {
grounded = true;
}
if (Input.GetMouseButtonDown && grounded == true) {
AnimationClip.play("jumping");
rigidbody2D.AddForce(transform.up*jumpPower);
grounded = false;
}
}
}
Thank You.
what is not working? your posted code cannot even compile as Get$$anonymous$$ouseButtonDown
is a method and you treat it as a property. (look here on how to use it)
Answer by Hexicon_Gamezel · Feb 14, 2016 at 05:58 PM
Oh. I just make it so when I press the space bar it will activate the animation, but when I release it. It will go back to idle. This is not the code for jumping this is just an example.
#pragma strict
function Start () {
}
function Update () {
if(Input.GetKeyDown("w"))
{
// Plays the reload animation - stops all other animations
animation.Play("run", PlayMode.StopAll);
}
}
Answer by TreyH · Feb 14, 2016 at 02:48 PM
http://docs.unity3d.com/ScriptReference/ForceMode.html
rigidbody2D.AddForce(transform.up*jumpPower, ForceMode.Impulse);
Follow this Question
Related Questions
Need Help Fixing my Double Jump with Animations in 3D 0 Answers
Animations get screwed up when I add OnAnimatorMove function 0 Answers
Falling blocks skip animation while upside down 1 Answer
How too climb a ladder with the FPS Controller correctly 0 Answers
What type of variable would I declare an animatable object as? (C#) 2 Answers