Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class cameraRaycast2 : MonoBehaviour {
  6.  
  7.     public LayerMask atuacaoRaycast;
  8.     public GameObject objeto;
  9.  
  10.     private RaycastHit[] alvos;
  11.  
  12.     // Update is called once per frame
  13.     void Update () {
  14.  
  15.         alvos = Physics.RaycastAll (transform.position, transform.forward, 100, atuacaoRaycast);
  16.  
  17.         if (alvos.Length > 0) {
  18.             Debug.DrawLine (transform.position, alvos [alvos.Length - 1].point);
  19.  
  20.             if (Input.GetMouseButtonDown (0)) {
  21.  
  22.                 foreach (RaycastHit alvo in alvos) {                   
  23.                     if (alvo.transform.name == "alvo") {
  24.                         Instantiate (objeto, alvo.point-transform.forward*0.5f, Quaternion.LookRotation (alvo.normal));            
  25.                     }
  26.                 }
  27.  
  28.             }
  29.         }
  30.  
  31.     }
  32.        
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement