Advertisement
Guest User

Untitled

a guest
May 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Destructable : MonoBehaviour
  6. {
  7.  
  8.     int health = 10;
  9.  
  10.     [SerializeField]
  11.     GameObject intactModel;
  12.  
  13.     [SerializeField]
  14.     List<GameObject> brokenModels;
  15.  
  16.     public int DecrimentHealth(int decriment) {
  17.         health -= decriment;
  18.         return health;
  19.     }
  20.  
  21.     public int DecrimentHealth() {
  22.         health -= health;
  23.         return health;
  24.     }
  25.  
  26.     void DestroyBarrel() {
  27.         intactModel.SetActive(false);
  28.  
  29.         foreach (GameObject gO in brokenModels) {
  30.             gO.SetActive(true);
  31.         }
  32.     }
  33.  
  34.  
  35.     // Start is called before the first frame update
  36.     void Start()
  37.     {
  38.        
  39.     }
  40.  
  41.     // Update is called once per frame
  42.     void FixedUpdate()
  43.     {
  44.         if (health <= 0) {
  45.             DestroyBarrel();
  46.         }
  47.         if (Input.GetKey(KeyCode.Space)) {
  48.             DecrimentHealth();
  49.         }
  50.  
  51.         if (Input.GetMouseButton(0))
  52.         {
  53.             Vector3 direction = transform.forward;
  54.             RaycastHit hit;
  55.             if (Physics.Raycast(transform.position, direction, hit))
  56.             {
  57.  
  58.                 if (hit.rigidbody)
  59.                     hit.rigidbody.AddForceAtPosition(10 * direction, hit.point);
  60.             }
  61.         }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement