public void doPunch() { Vector3 destination = transform.position + (transform.right * speed); Vector3 dir = (destination - transform.position).normalized; transform.position += dir * speed * Time.deltaTime; if (Vector3.Distance(player.transform.position, transform.position) >= distance) { stateOfPunch = punchState.backwards; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(punchKey)) { if (stateOfPunch == punchState.ready) { punchStart = transform.localPosition; stateOfPunch = punchState.forward; } } if (stateOfPunch == punchState.forward) { doPunch(); } if (stateOfPunch == punchState.backwards) { resetPunch(); } }
public void resetPunch() { transform.localPosition = punchStart; stateOfPunch = punchState.ready; }
private void Start() { stateOfPunch = punchState.ready; }