Advertisement
sphinx2001

NewShootControl

Mar 21st, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class NewShootControl : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     public int bulletSpeed = 50;
  9.     public Camera _camera;
  10.     public GameObject pointGun;
  11.     public GameObject bullet;
  12.         // Update is called once per frame
  13.     void Update()
  14.     {
  15.         if (Input.GetMouseButtonDown(0))
  16.         {
  17.             GameObject pref = Instantiate(bullet
  18.                                       , transform.position + transform.forward * 2f,
  19.                                       _camera.transform.rotation) as GameObject;
  20.            
  21.             Physics.IgnoreCollision(transform.root.GetComponent<Collider>(), pref.GetComponent<Collider>());//отключение коллизий
  22.             Rigidbody rb = pref.GetComponent<Rigidbody>();
  23.             rb.AddForce(_camera.transform.rotation * new Vector3(0f, 0f, bulletSpeed));
  24.             Destroy(pref, 2);
  25.             //Debug.Log(_camera.transform.rotation * new Vector3(0f, 0f, bulletSpeed));
  26.         }      
  27.        
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement