【发布时间】:2021-07-27 08:56:35
【问题描述】:
***
使用 System.Collections;使用 System.Collections.Generic;使用 统一引擎;公共类击退:MonoBehaviour { 公共浮动推力; 公共浮动敲击时间;
// Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.CompareTag("enemy")) { Rigidbody2D enemy = other.GetComponent<Rigidbody2D>(); if(enemy != null) { StartCoroutine(KnockCo(enemy)); } } } private IEnumerator KnockCo(Rigidbody2D enemy) { if(enemy != null) { Vector2 forceDirection = enemy.transform.position - transform.position; Vector2 force = forceDirection.Normalize() * thrust; enemy.velocity = force; yield return new WaitForSeconds(KnockTime); enemy.velocity = new Vector2(); { } } } }
【问题讨论】:
标签: c#