將另外地鼠的洞口圖片拖動到Scene場景中。 (這一步如果將洞口圖片拖動到場景中還是看不到效果的話,可以使用以下方法進行調整: 選中ground圖片,將Inspector屬性面板中“Order in Layer”數值調整為0,代表在第0層; 選中Hole圖片,將Inspector屬性面板中“Order in Layer”數值調整為1,代表在第1層。 這樣,就可以確保洞口圖像是處在背景圖像上方的)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class S1 : MonoBehaviour
{// Use this for initializationvoid Start(){}void OnMouseDown(){Debug.Log("you hit me ");}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class S1 : MonoBehaviour
{// Use this for initializationvoid Start(){}void OnMouseDown(){Debug.Log("you hit me ");}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class S2 : MonoBehaviour {public GameObject m_Prefab2;// Use this for initializationvoid Start () {}private void OnMouseDown(){Instantiate(m_Prefab2, transform.position, Quaternion.identity);Destroy(gameObject);}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class S3 : MonoBehaviour {// Use this for initializationvoid Start () {Destroy(gameObject, 0.5f);}// Update is called once per framevoid Update () {}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class CreateTarget : MonoBehaviour {public GameObject m_Target;void Start () {//Create();InvokeRepeating("Create", 0, 1);}void Create(){Vector3 pos = Vector3.zero;int id = 0;id = Random.Range(1, 10);if(id==1)pos = new Vector3(0, 0, 0);if (id == 2)pos = new Vector3(2, 0, 0);if (id == 3)pos = new Vector3(4, 0, 0);if (id == 4)pos = new Vector3(0, 1, 0);if (id == 5)pos = new Vector3(2, 1, 0);if (id == 6)pos = new Vector3(4, 1, 0);if (id == 7)pos = new Vector3(0, 2, 0);if (id == 8)pos = new Vector3(2, 2, 0);if (id == 9)pos = new Vector3(4, 2, 0);Instantiate(m_Target, pos, Quaternion.identity);//Instantiate(m_Target,)}
}