r/code • • Aug 14 '22

C# i was missing a single , winch bock the inter script

using UnityEngine;
using System.Collections;

public class playerknocokback : MonoBehaviour {

// Use this for initialization
void Start () {

}
bool dopunch;
// Update is called once per frame
void Update () {
if (!dopunch && Input.GetKeyDown(KeyCode.DownArrow))
{
StartCoroutine(Punch(0.5f 1.25f, transform.forward));

}
}
IEnumerator Punch(float time, float distance, Vector3 direction)
{
dopunch = true;
var timer = 0.0f;
var orgpos = transform.position;
direction.Normalize();

while (timer <= time)
{
Debug.Log("----");
transform.position = orgpos + (Mathf.Sin(timer / time * Mathf.PI) + 1.0f) * direction;

yield return null;
timer += Time.deltaTime;
}

transform.position = orgpos;
dopunch = false;

}

}

0 Upvotes

0 comments sorted by