using UnityEngine;
using System.Collections;
public class GameRootScript : MonoBehaviour {
public GameObject prefab = null;
private AudioSource audio;
public AudioClip jumpSound;
public Texture2D icon = null;
public static string mes_text = "test";
// Use this for initialization
void Start () {
this.audio = this.gameObject.AddComponent<AudioSource> ();
this.audio.clip = this.jumpSound;
this.audio.loop = false;
}
void onGUI()
{
Debug.Log ("Image");
GUI.DrawTexture (new Rect (Screen.width/2, 64, 64, 64), icon);
GUI.Label (new Rect (Screen.width / 2, 128, 128, 32), mes_text);
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown (KeyCode.Z)){
Debug.Log("Prefab");
GameObject go = GameObject.Instantiate(this.prefab) as GameObject;
go.transform.position = new Vector3(Random.Range(-2.0f,2.0f), 1.0f, 1.0f);
this.audio.Play();
}
}
}
我在Unity中创建了onGUI()方法,但该方法不起作用 我只是按照这本书,我不知道是什么原因造成的 即使我编译该代码也没有错误 书籍版本为4.xx,Unity版本为5.1.2。