using UnityEngine;
using System.Collections;
public class PlayerIO : MonoBehaviour {
RaycastHit hit;
int MaxBuildDist = 10;
public Transform RetAdd;
public Transform RetDelete;
Color Block_Color = Color.blue;
bool Block_Menu = false;
// Use this for initialization
void Start (){
RetAdd = GameObject.Find("RetAdd").transform;
RetDelete = GameObject.Find("RetDelete").transform;
}
// Update is called once per frame
void Update (){
if (Input.GetKeyDown(KeyCode.E))
Block_Menu = !Block_Menu;
if (Block_Menu)
Time.timeScale = 0;
if
(!Block_Menu){
if(Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3((Screen.width / 2), (Screen.height / 2), 0)), out hit, MaxBuildDist)){
RetAdd.GetComponent().enabled = true;
if(hit.transform.tag == "Block"){
RetAdd.transform.position = hit.transform.position + hit.normal;
RetDelete.transform.position = hit.transform.position;
RetDelete.GetComponent().enabled = true;
}
if(hit.transform.tag != "Block"){
RetDelete.GetComponent().enabled = false;
RetAdd.transform.position = new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z);
}
if(Input.GetMouseButtonDown(0)){
GameObject block = (GameObject)Instantiate(Resources.Load("Block01"), RetAdd.transform.position, Quaternion.identity);
block.GetComponent().material.color = Block_Color;
}
else if(Input.GetMouseButtonDown(1) && hit.transform.tag != "Floor"){
Destroy(hit.transform.gameObject);
}
else{
RetAdd.GetComponent().enabled = false;
RetDelete.GetComponent().enabled = false;
}
}
}
void OnGUI(){
if(Block_Menu)
Block_Menu_GUI();
}
void Block_Menu_GUI(){
GUILayout.BeginVertical();
if(GUILayout.Button("Green"))
Block_Color = Color.green;
if(GUILayout.Button("Red"))
Block_Color = Color.red
if(GUILayout.Button("Blue"))
Block_Color = Color.blue
GUILayout.EndVertical();
}
}
↧