Код: Выделить всё
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 ();
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 — 4.xx, а моя версия Unity — 5.1. 2.
Подробнее здесь: https://stackoverflow.com/questions/319 ... d-in-unity
Мобильная версия