Advertisement
Guest User

Untitled

a guest
Jun 27th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Linq.Expressions;
  4.  
  5. public class sultan : MonoBehaviour
  6. {
  7.  
  8.     private GameObject sultanPref;
  9.     // Use this for initialization
  10.     void Start () {
  11.         sultanPref=Resources.Load("sultan") as GameObject;;
  12.     }
  13.    
  14.     // Update is called once per frame
  15.     void Update () {
  16.         if (Input.GetKeyDown(KeyCode.Space))
  17.         {
  18.             RaycastHit hit = new RaycastHit();
  19.             Ray ray = new Ray(transform.position, transform.forward);
  20.  
  21.             if (Physics.Raycast(ray, out hit, 100))
  22.             {
  23.                 GameObject go = (GameObject) Instantiate(sultanPref, hit.point, Quaternion.LookRotation(transform.forward));
  24.                 go.transform.GetComponent<Renderer>().material = hit.collider.transform.GetComponent<Renderer>().material;
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement