SHARE
TWEET

Untitled

a guest Mar 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. public class InstantiateObject : MonoBehaviour {
  7.  
  8.     Ray ray;
  9.     RaycastHit hit;
  10.     public GameObject hammer;
  11.     public GameObject wrench;
  12.     public GameObject screwdriver;
  13.     public GameObject hexBolt;
  14.     public GameObject allenBolt;
  15.     public GameObject screwPhillips;
  16.     public GameObject screwStandard;
  17.     //public GameObject toolSpawnpoint;
  18.     // Use this for initialization
  19.     void Start()
  20.     {
  21.  
  22.     }
  23.  
  24.  
  25.     // Update is called once per frame
  26.     void FixedUpdate()
  27.     {
  28.         if (Input.GetMouseButtonDown(0))
  29.         {
  30.             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  31.  
  32.             if (Physics.Raycast(ray, out hit))
  33.             {
  34.                 if(hit.transform.name == "Wrench")
  35.                 {
  36.  
  37.                     //Wrench 1"(25mm)
  38.                     Debug.Log("Wrench");
  39.                     //Creates a new object(clone) at the x,y,z position of the wrench, and with a custom rotation for x,y,z.
  40.                     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;
  41.                     //Scales the gameobject clone to the following x,y,z scale values
  42.                     obj.transform.localScale = new Vector3(0.009336234f, 0.009336234f, 0.009336234f);
  43.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  44.                     //Locks the rotation of the object's x,y,z(Prevents the object from rotating
  45.                     obj.GetComponent<Rigidbody>().freezeRotation = true;
  46.                 }
  47.                 if (hit.transform.name == "Hammer")
  48.                 {
  49.                     Debug.Log("Hammer");
  50.                     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;
  51.                     obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
  52.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  53.                     obj.GetComponent<Rigidbody>().freezeRotation = true;
  54.  
  55.                 }
  56.                 if (hit.transform.name == "Screwdriver Standard")
  57.                 {
  58.                     Debug.Log("Screwdriver Standard");
  59.                     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;
  60.                     obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
  61.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  62.                     obj.GetComponent<Rigidbody>().freezeRotation = true;
  63.                 }
  64.                 if (hit.transform.name == "HEX BOLT Med")
  65.                 {
  66.                     Debug.Log("HEX BOLT Med");
  67.                     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;
  68.                     obj.transform.localScale = new Vector3(0.009346771f, 0.00934677f, 0.00934677f);
  69.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  70.                 }
  71.                 if (hit.transform.name == "ALLEN BOLT Med")
  72.                 {
  73.                     Debug.Log("ALLEN BOLT Med");
  74.                     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;
  75.                     obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
  76.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  77.                 }
  78.                 if (hit.transform.name == "Screw Phillips head")
  79.                 {
  80.                     Debug.Log("Screw Phillips head");
  81.                     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;
  82.                     obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
  83.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  84.                 }
  85.                 if (hit.transform.name == "Screw Standard head")
  86.                 {
  87.                     Debug.Log("Screw Standard head");
  88.                     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;
  89.                     obj.transform.localScale = new Vector3(0.009346766f, 0.009346766f, 0.009346766f);
  90.                     obj.GetComponent<Rigidbody>().isKinematic = false;
  91.                 }
  92.  
  93.             }
  94.         }
  95.         if (Input.GetMouseButtonDown(1))
  96.         {
  97.             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  98.  
  99.             if (Physics.Raycast(ray, out hit))
  100.             {
  101.                
  102.                 if (hit.transform.name == "Wrench(Clone)")
  103.                 {
  104.                     Destroy(hit.transform.gameObject);
  105.                 }
  106.                 if (hit.transform.name == "Hammer(Clone)")
  107.                 {
  108.                     Destroy(hit.transform.gameObject);
  109.                 }
  110.                 if (hit.transform.name == "Screwdriver Standard(Clone)")
  111.                 {
  112.                     Destroy(hit.transform.gameObject);
  113.                 }
  114.                 if (hit.transform.name == "HEX BOLT Med(Clone)")
  115.                 {
  116.                     Destroy(hit.transform.gameObject);
  117.                 }
  118.                 if (hit.transform.name == "ALLEN BOLT Med(Clone)")
  119.                 {
  120.                     Destroy(hit.transform.gameObject);
  121.                 }
  122.                 if (hit.transform.name == "Screw Phillips head(Clone)")
  123.                 {
  124.                     Destroy(hit.transform.gameObject);
  125.                 }
  126.                 if (hit.transform.name == "Screw Standard head(Clone)")
  127.                 {
  128.                     Destroy(hit.transform.gameObject);
  129.                 }
  130.             }
  131.         }
  132.     }
  133. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top