Search Unity

Games My Scripts aren't interacting with my scene.

Discussion in 'Works In Progress - Archive' started by Fenix_Abbott, Jun 7, 2020.

  1. Fenix_Abbott

    Fenix_Abbott

    Joined:
    Jun 4, 2020
    Posts:
    4
    I'm creating a mobile type game in Unity and the point is that every time you lose some health the polyhedron that the player is, loses an entire side of it. The problem is that my scripts seem to have no effect in unity. The two scripts that I am having the most issues with are these. Mind you I'm not getting any error codes or warnings.
    Code (CSharp):
    1. using UnityEngine;
    2. public class PlayerHealth : MonoBehaviour
    3. {
    4.     public GameObject player;
    5.     public GameObject tri;
    6.     public GameObject quad;
    7.     public GameObject pent;
    8.     public GameObject hex;
    9.     public GameObject sept;
    10.     public int health;
    11.     void Awake()
    12.     {
    13.         quad.SetActive(true);
    14.         health = 2;
    15.     }
    16.     void FixedUpdate()
    17.     {
    18.         if(health == 0)
    19.         {
    20.             Destroy(player);
    21.         }
    22.         if(health == 1)
    23.         {
    24.             tri.SetActive(true);
    25.             quad.SetActive(false);
    26.         }
    27.         if(health == 2)
    28.         {
    29.             tri.SetActive(false);
    30.             quad.SetActive(true);
    31.             pent.SetActive(false);
    32.         }
    33.         if (health == 3)
    34.         {
    35.             quad.SetActive(false);
    36.             pent.SetActive(true);
    37.             hex.SetActive(false);
    38.         }
    39.         if (health == 4)
    40.         {
    41.             pent.SetActive(false);
    42.             hex.SetActive(true);
    43.             sept.SetActive(false);
    44.         }
    45.         if (health == 5)
    46.         {
    47.             hex.SetActive(false);
    48.             sept.SetActive(true);
    49.         }
    50.         if(health > 7)
    51.         {
    52.             health = 7;
    53.         }
    54.     }
    55. }
    56.  
    And the second one:
    Code (CSharp):
    1. using UnityEngine;
    2. public class PlayerCollider : MonoBehaviour
    3. {
    4.     public GameObject player;
    5.     private PlayerHealth playerHealth;
    6.     void Start()
    7.     {
    8.         playerHealth = player.GetComponent<PlayerHealth>();
    9.     }
    10.     void OnCollisionEnter(Collision collision)
    11.     {
    12.         playerHealth.health = playerHealth.health - 1;
    13.     }
    14. }
    The public GameObject Player is an empty object that contains all of the other mentioned scripts and prefabs.