Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [SerializeField] private List<GameObject> placeableobjects = new List<GameObject>();
- [SerializeField] private LayerMask terrainlayer;
- private GameObject selectedobject;
- void Update()
- {
- moveselectedobject();
- }
- public void instantiateGameObject(int i)
- {
- selectedobject = Instantiate(placeableobjects[i]); // another script is passing an int to this method
- }
- private void moveselectedobject()
- {
- if (selectedobject != null)
- {
- RaycastHit hit;
- if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 300, terrainlayer))
- {
- selectedobject.transform.position = new Vector3(hit.point.x, selectedobject.GetComponent<Collider>().bounds.size.y / 2, hit.point.z);
- }
- if (Input.GetKey(KeyCode.Y))
- {
- selectedobject.transform.eulerAngles += new Vector3(0, 1, 0);
- }
- if (Input.GetMouseButtonDown(0))
- {
- GameObject instance = Instantiate(placeableobjects[2], new Vector3(hit.point.x, 0.025f, hit.point.z), Quaternion.identity);
- instance.transform.rotation = selectedobject.transform.rotation;
- Destroy(selectedobject);
- selectedobject = null;
- }
- else if (Input.GetKeyDown(KeyCode.Escape))
- {
- Destroy(selectedobject);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement