I want to make it so that once clicking on a button it will make something and when you click on it again it will make something else.
using UnityEngine;
using System.Collections;
public class Ai : MonoBehaviour {
bool stopstate = false;
Animator _anim;
// Use this for initialization
void Start () {
_anim = GetComponent<Animator> ();
//_animation = GetComponent<Animation> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.Z)) {
if (stopstate == false) {
stopstate = true;
_anim.Stop ();
} else {
stopstate = false;
_anim.StartPlayback ();
}
}
}
}
Once I clicked on Z Stop() but if I press it again on Z now Play.
The problem is that the code is in the Update function so I use a break point once I pressed the Z key it stopped on the _anim.StartPlayback (); but it should get there on the second time i click on Z.
Second problem is when it does the line _anim.StartPlayback (); it's not making the character to continue walking from the point it was stopped.
_anim.Stop(); really stop it but StartPlayback() not make it continue.