The question is answered, right answer was accepted
Script error
Hi, I'm creating a game and I have a problem with one of the Scripts. This is the script and there are the two errors, any idea of how i can fix it? This is a script to get my chatacter to attack and get back to the Idle position.
Okay so I have this right now: public class Attack2 : $$anonymous$$onoBehaviour { protected Animator animator;
// Use this for initialization
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
// Update is called once per frame
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0))
{
animator.SetBool("Attack", true);
}
else {
animator.SetBool("Attack", false);
}
}
}
it's perfect, no errors, but now I click on the left button and nothing happens. I think the code is O$$anonymous$$ so idk what's wrong. $$anonymous$$y animator tree is set with a variable type Bool called Attack which goes from idle to Attack when true and comes back when false...
Ive never tried your method for getting mouse buttons. The mouse buttons actually have their own special input, Input.Get$$anonymous$$ouseButton. There's also a variation, Get$$anonymous$$ouseButtonDown, and Get$$anonymous$$ouseButtonUp. Then you specify which button. (0) for left button, (1) for right button, and (2) for middle. All in all, it looks something like this:
if(Input.Get$$anonymous$$ouseButton(0)){
}
Still, your code seems fine and should still run. Is your script attached to an object? Is the animator set up properly? Put Debug.Log("true") inside the if statement to see if the code ever runs. If so, it's not a problem with the script.
Sure! There it is: using UnityEngine; using System.Collections;
public class Attack2 : $$anonymous$$onoBehaviour { protected Animator animator;
// Use this for initialization
void Start() {
animator = GetComponent<Animator>();
}
// Update is called once per frame
// Update is called once per frame
void Update() {
if (Input.GetButton("$$anonymous$$ouse0"));
{
animator.SetBool("Attack", true);
}
else {
animator.SetBool("Attack", false);
}
}
}
using UnityEngine; using System.Collections;
public class Logo : $$anonymous$$onoBehaviour { protected Animator animator;
// Use this for initialization
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
// Update is called once per frame
void Update()
{
if (Input.GetButton("$$anonymous$$ouse0"))
{
animator.SetBool("Attack", true);
}
else {
animator.SetBool("Attack", false);
}
}
}
Don't use ; after (). if (Input.GetButton("$$anonymous$$ouse0")); {...} NO if (Input.GetButton("$$anonymous$$ouse0")) {...} O$$anonymous$$
It would be more useful if you added the error messages as code too, but yea the problem is your semi colon on your if statement.