using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroler : MonoBehaviour {
public static playercontroler sharedinstance;
void Awake(){
sharedinstance = this;
rigidBody = GetComponent<Rigidbody2D> ();
}
public void KillPlayer(){
GameManager.sharedistance.GameOver ();
animator.SetBool ("isAlive", false);
}
}
和
public class killtriger : MonoBehaviour {
void OnTriggerEnter2D(Collider2D theObject){
if (theObject.tag == "Player") {
playercontroler.sharedinstance.KillPlayer ();
}
}
}
问题在于团结回归:
“playercontroler”不包含sharedinstance的定义
有什么问题?感谢
答案 0 :(得分:0)
不知道这是否会解决所有问题,但您应该在使用之前检查是否已设置了playercontroler.sharedinstance。
public class killtriger : MonoBehaviour {
void OnTriggerEnter2D(Collider2D theObject){
if (theObject.tag == "Player" && playercontroler.sharedinstance) {
playercontroler.sharedinstance.KillPlayer ();
}
}
}
还要确保变量名称正确。您的代码中有变量sharedistance和sharedinstance。它们用于不同的对象,但我想它们应该具有相同的名称。