Advertisement
Savelyev_Vyacheslav

Unity3d no-turning VRAG

Jun 6th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Vrag : MonoBehaviour
  6. {
  7.     public GameObject Shot2;
  8.     public GameObject Gun2;
  9.     public float shotDelay2;
  10.     public float speed;
  11.     float nextShotTime2;
  12.     float countshoot2;
  13.  
  14.  
  15.     Rigidbody vrag;
  16.     // Start is called before the first frame update
  17.     void Start()
  18.     {
  19.         vrag = GetComponent<Rigidbody>();
  20.         //  vrag.velocity = new Vector3(2, 0, 5);
  21.     }
  22.  
  23.     // Update is called once per frame
  24.     void Update()
  25.     {
  26.         float moveHorizontal = Input.GetAxis("Horizontal");
  27.         float moveVertical = Input.GetAxis("Vertical");
  28.         vrag.velocity = new Vector3(moveHorizontal, 0, 0) * speed;
  29.  
  30.         //без поворота
  31.  
  32.         vrag.transform.localRotation = Quaternion.Slerp(vrag.transform.rotation,
  33.       Quaternion.Euler(0, 0, 0), speed * Time.deltaTime);
  34.  
  35.  
  36.  
  37.         //  Instantiate(Shot2, Gun2.transform.position, Quaternion.identity);
  38.  
  39.         if (Time.time > nextShotTime2)
  40.         {
  41.             Instantiate(Shot2, Gun2.transform.position, Quaternion.identity);
  42.             nextShotTime2 = Time.time + shotDelay2;
  43.    
  44.         }
  45.  
  46.     }
  47.  
  48.     void OnTriggerEnter(Collider other)
  49.     {
  50.         countshoot2++;
  51.         print(countshoot2);
  52.         if (countshoot2 > 10)
  53.  
  54.         {
  55.             countshoot2 = 0;
  56.             if (other.tag == "shiptrig")
  57.                 Destroy(other.gameObject);
  58.             Destroy(gameObject);
  59.         }
  60.  
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement