下周学习 2021/5/5
提供专属的一对一在线答疑,快速答疑解惑。
及时响应学习咨询,帮助解决问题。
购买后7天内可申请无理由退款。
购买后30天内如遇降价,可申请价保。
对于提问做到有问必答,帮您扫清学习过程中的种种障碍
总是要去找Ctrl 何不做一个单例类呢
public abstract class InstanceMonoBehavior<T> : MonoBehaviour
{
private static T _instance;
public static T GetInstance()
{
return _instance;
}
protected virtual void Awake()
{
_instance = ReturnInstance();
}
protected abstract T ReturnInstance();
}
接下来将Ctrl 继承他
public class Ctrl : InstanceMonoBehavior<Ctrl>{
protected override Ctrl ReturnInstance()
{
return this;
}
}
在任何地方都可以使用Ctrl.GetInstance() 获得单例对象
1.GameManager//核心逻辑属于控制层
Bool IsPause 游戏是否暂停
public Shape[] shapes;
给图形添加脚本Shape
public Clolor[] colors;
void SpawnShape(){
int index=Random.range(0,shape.lenth);
int indexColor=random.range(0,color.lenth);
Shape shape=Gameobject.Instantiate(shapes[index]);
shape.init(colors[indexClolor]);
}