using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Room : MonoBehaviour {
public ClassB classBTestInstance = new ClassB(3);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
public class ClassB {
public ClassB(int testNum) {
Debug.Log("hello " + testNum);
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
你可以看到它说"Hello 3"两次.我希望了解为什么会出现这种情况?我没看到我把它叫了两次.在image2中,您将看到只有一个房间实例(当我将房间类C#脚本附加到主摄像机时).我没有将此脚本附加到其他任何内容上.