Unity C# Script error: CS1501
With the game I'm making, I'm trying to connect the jump animation to the player so when you press space the jump animation will play. Now up to this point I've followed this tutorial: https://www.youtube.com/watch?v=h8oI0n5kAIg and https://www.youtube.com/watch?v=z6h3aE9LIxk
to connect both the idle and walk animations to the player model and both work fine. Now I've tried the same method with the jump animation and got a parsing error(which after a bit of fiddling and experimenting I fixed) this is what the code looked like before I fixed it:
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start () {
anim = gameObject.GetComponentInChildren<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimPar", 1);
} else {
anim.SetInteger ("AnimPar", 0);
}
if (Input.GetKey ("space")){
anim.SetInteger ("AnimPar", 2);
} else {
anim.SetInteger ("AnimPar", 0);
}
}
}
Now when I fixed it, I encountered this error: "error: CS1501: no overload for method 'SetInteger' takes `1' arguments"
This is what my current C# script looks like:
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start () {
anim = gameObject.GetComponentInChildren<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimPar", 1);
} else {
anim.SetInteger ("AnimPar", 0);
}
if (Input.GetKeyDown ("space")){
anim.SetInteger ("Jump");
} else {
anim.SetInteger ("Jump");
}
}
}
I'm very new to Unity and I'm just learning how to write these codes through youtube video tutorials. So far the most difficult thing I've run into is trying to get the jump animation to trigger when the character jumps ^_^; I would greatly appreciate any help on where I've gone wrong here :)
Answer by Alpha_PsychO · Sep 25, 2016 at 05:22 AM
Hi @CraftyMaelyss, I'm pretty new to Unity as well, but I think your problem is that on lines 20 and 22 your "Jump" needs to have an integer, like you used with
("AnimPar", 1)
So, whatever integer you are using to get your animation to switch to jump add it in. ("Jump", /integer that tells jump which animation to use/)
Also, if that doesn't help I used these vids to learn how to animate. I see from the vids you watched your making a 3D game (at least I'm assuming), and these vids are for 2D. I'm not sure how different it will be from 3D to 2D, but maybe they could help. In fact, the entire playlist for these tutorials is very useful and well made. The links below are only for the two about animating.
https://www.youtube.com/watch?v=Oao-A7bkve0&list=PLiyfvmtjWC_X6e0EYLPczO9tNCkm2dzkm∈dex=3
https://www.youtube.com/watch?v=M1bEtHOE8z8∈dex=4&list=PLiyfvmtjWC_X6e0EYLPczO9tNCkm2dzkm
I hope this helps. :)