Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Destructable : MonoBehaviour
- {
- int health = 10;
- [SerializeField]
- GameObject intactModel;
- [SerializeField]
- List<GameObject> brokenModels;
- public int DecrimentHealth(int decriment) {
- health -= decriment;
- return health;
- }
- public int DecrimentHealth() {
- health -= health;
- return health;
- }
- void DestroyBarrel() {
- intactModel.SetActive(false);
- foreach (GameObject gO in brokenModels) {
- gO.SetActive(true);
- }
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- if (health <= 0) {
- DestroyBarrel();
- }
- if (Input.GetKey(KeyCode.Space)) {
- DecrimentHealth();
- }
- if (Input.GetMouseButton(0))
- {
- Vector3 direction = transform.forward;
- RaycastHit hit;
- if (Physics.Raycast(transform.position, direction, hit))
- {
- if (hit.rigidbody)
- hit.rigidbody.AddForceAtPosition(10 * direction, hit.point);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement