当我点击上箭头时,我希望我的小立方体变为更大的立方体,当我按下向下箭头时,我想要改回来。我试过了:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSkift : MonoBehaviour {
public gameObject myObject1;
public gameObject myObject2;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.UpArrow))
{
myObject1.SetActive (false);
myObject2.SetActive (true);
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
myObject2.SetActive(false);
myObject1.SetActive(true);
}
}
}
当我尝试运行时,它说:
Assets/PlayerSkift.cs(9,9): error CS0118: `UnityEngine.Component.gameObject' is a `property' but a `type' was expected
我不知道这意味着什么,所以如果你知道,或者知道如何以其他方式做到这一点。请帮忙。
答案 0 :(得分:2)
public gameObject myObject1;
public gameObject myObject2;
根据this discussion,上述代码似乎有错字。
gameObject
应为GameObject
。