Hi Everyone It´s me again Can somebody help with this script . I did it after looking a tutorial on youtube . the Problem is i can´t add a script which can make my character attack zombie . He just walks from right and left like inside tht tuto but i don´t know how i can make him attack by animation using animator. i did a screenshot of my code.
First of all... screenshot of code? Just paste it. Second, your script calls animation.Play. "animation" points to an Animation component, which is not what you have: you have an Animator. (Since Unity has a "legacy" animation system plus Mecanim, the names of these components can get confusing) The script is already creating a reference to the Animator component ("go"), use that. You'll have to set the "attack1" trigger.
thx u but i´m still learning how to programm and what u said i´ve got but i do not really know how to write it can u help?
here is the Script i did it like u told me but it didn´t work using UnityEngine; using System.Collections; public class gaby : MonoBehaviour { public float maxSpeed = 5f; bool turnBack = true; Animator go; // Use this for initialization void Start () { go = GetComponent<Animator> (); } // Update is called once per frame void Update () { float move = Input.GetAxis("Horizontal"); go.SetFloat ("speed", Mathf.Abs (move)); rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y); if (move > 0 && !turnBack) turningBack (); else if (Input.GetKeyDown (KeyCode.Q)) { // i have no Idea how to make my character attack after creating an Animation in animator } else if (move < 0 && turnBack) turningBack (); } void turningBack() { turnBack = ! turnBack; Vector3 theScale = transform.localScale; theScale.x*=-1; transform.localScale = theScale; } }