Advertisement
Guest User

finalaenot

a guest
Dec 3rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Disparo : MonoBehaviour
  6. {
  7.     public Camera tankCam;
  8.     float range = 100f;
  9.     public GameObject bala;
  10.     float force = 6000f;
  11.     float expRad = 10000f;
  12.  
  13.     void Start()
  14.     {
  15.        
  16.     }
  17.  
  18.     void Update()
  19.     {
  20.         if (Input.GetKeyDown(KeyCode.Space))
  21.         {
  22.             Shoot();
  23.         }
  24.     }
  25.     void Shoot()
  26.     {
  27.         RaycastHit hit;
  28.         if (Physics.Raycast(tankCam.transform.position, tankCam.transform.forward, out hit, range))
  29.         {
  30.             Instantiate(bala, hit.point, Quaternion.identity);
  31.            
  32.         }
  33.         if (hit.rigidbody)
  34.             {
  35.             hit.rigidbody.AddExplosionForce(force, tankCam.transform.forward, expRad);
  36.             }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement