Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class InstantiateObject : MonoBehaviour {
- Ray ray;
- RaycastHit hit;
- public GameObject hammer;
- public GameObject wrench;
- public GameObject screwdriver;
- public GameObject hexBolt;
- public GameObject allenBolt;
- public GameObject screwPhillips;
- public GameObject screwStandard;
- //public GameObject toolSpawnpoint;
- // Use this for initialization
- void Start()
- {
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- if (Input.GetMouseButtonDown(0))
- {
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit))
- {
- if(hit.transform.name == "Wrench")
- {
- //Wrench 1"(25mm)
- Debug.Log("Wrench");
- //Creates a new object(clone) at the x,y,z position of the wrench, and with a custom rotation for x,y,z.
- GameObject obj = Instantiate(wrench, new Vector3(wrench.transform.position.x + 0.02f, wrench.transform.position.y, wrench.transform.position.z), Quaternion.Euler(0, -90, -90)) as GameObject;
- //Scales the gameobject clone to the following x,y,z scale values
- obj.transform.localScale = new Vector3(0.009336234f, 0.009336234f, 0.009336234f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- //Locks the rotation of the object's x,y,z(Prevents the object from rotating
- obj.GetComponent<Rigidbody>().freezeRotation = true;
- }
- if (hit.transform.name == "Hammer")
- {
- Debug.Log("Hammer");
- GameObject obj = Instantiate(hammer, new Vector3(hammer.transform.position.x + 0.2f, hammer.transform.position.y, hammer.transform.position.z + 0.03f), Quaternion.Euler(0,-180,-90)) as GameObject;
- obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- obj.GetComponent<Rigidbody>().freezeRotation = true;
- }
- if (hit.transform.name == "Screwdriver Standard")
- {
- Debug.Log("Screwdriver Standard");
- GameObject obj = Instantiate(screwdriver, new Vector3(screwdriver.transform.position.x, screwdriver.transform.position.y, screwdriver.transform.position.z + 0.03f), Quaternion.Euler(0, -90, 90)) as GameObject;
- obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- obj.GetComponent<Rigidbody>().freezeRotation = true;
- }
- if (hit.transform.name == "HEX BOLT Med")
- {
- Debug.Log("HEX BOLT Med");
- GameObject obj = Instantiate(hexBolt, new Vector3(hexBolt.transform.position.x, hexBolt.transform.position.y, hexBolt.transform.position.z), Quaternion.Euler(0, -90, 90)) as GameObject;
- obj.transform.localScale = new Vector3(0.009346771f, 0.00934677f, 0.00934677f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- }
- if (hit.transform.name == "ALLEN BOLT Med")
- {
- Debug.Log("ALLEN BOLT Med");
- GameObject obj = Instantiate(allenBolt, new Vector3(allenBolt.transform.position.x, allenBolt.transform.position.y, allenBolt.transform.position.z), Quaternion.Euler(0, -90, 90)) as GameObject;
- obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- }
- if (hit.transform.name == "Screw Phillips head")
- {
- Debug.Log("Screw Phillips head");
- GameObject obj = Instantiate(screwPhillips, new Vector3(screwPhillips.transform.position.x, screwPhillips.transform.position.y, screwPhillips.transform.position.z), Quaternion.Euler(0, -90, 90)) as GameObject;
- obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- }
- if (hit.transform.name == "Screw Standard head")
- {
- Debug.Log("Screw Standard head");
- GameObject obj = Instantiate(screwStandard, new Vector3(screwStandard.transform.position.x, screwStandard.transform.position.y, screwStandard.transform.position.z), Quaternion.Euler(0, -90, 90)) as GameObject;
- obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
- obj.GetComponent<Rigidbody>().isKinematic = false;
- }
- }
- }
- if (Input.GetMouseButtonDown(1))
- {
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit))
- {
- if (hit.transform.name == "Wrench(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- if (hit.transform.name == "Hammer(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- if (hit.transform.name == "Screwdriver Standard(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- if (hit.transform.name == "HEX BOLT Med(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- if (hit.transform.name == "ALLEN BOLT Med(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- if (hit.transform.name == "Screw Phillips head(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- if (hit.transform.name == "Screw Standard head(Clone)")
- {
- Destroy(hit.transform.gameObject);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement