【发布时间】:2020-06-30 09:24:26
【问题描述】:
我正在尝试制作一个可以砍树的游戏,但是当我测试我的脚本时它根本不起作用。此脚本用于砍伐树木。当我将 TakeDmg 和 Destroytree 放在私有 void OnTriggerEnter2D(Collider2D other) 中时,它工作正常,但是当我添加 if(Input.GetKey(KeyCode.E)) 时,它停止工作,我真的不知道这是问题所在。
public int treeHp;
public GameObject logPrefab;
public Animator anim;
private void OnTriggerEnter2D(Collider2D other){
if(Input.GetKey(KeyCode.E)){
TakeDmg();
Destroytree();
}
}
public void TakeDmg(){
anim.SetTrigger("TreeDamage");
treeHp = treeHp -1;
}
public void Destroytree(){
if(treeHp <= 0){
//spawn la loguri
Destroy(gameObject);
}
}
谢谢:D
【问题讨论】: