Search Unity

Where is the properties?

Discussion in 'Scripting' started by neyu_unity, Jun 15, 2018.

  1. neyu_unity

    neyu_unity

    Joined:
    Jun 15, 2018
    Posts:
    6
    Adsız2.png My codes :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player : MonoBehaviour
    6. {
    7.  
    8.     // variables
    9.     public float maxHealth, maxThirst, maxHunger;
    10.     public float thirstIncreaseRate, hungerIncreaseRate;
    11.     private float health, thirst, hunger;
    12.  
    13.  
    14.     // functions
    15.     public void Start()
    16.     {
    17.         health - maxHealth;
    18.     }
    19.  
    20.     public void Update()
    21.     {
    22.  
    23.         //thirst and hunger increase
    24.         if (thirst < maxThirst)
    25.         {
    26.             thirst + -thirstIncreaseRate * Time.deltaTime;
    27.         }
    28.  
    29.  
    30.         if (hunger < maxHunger)
    31.         {
    32.             hunger + -hungerIncreaseRate * Time.deltaTime;
    33.         }
    34.  
    35.         if (thirst > -maxThirst)
    36.             Die();
    37.         if (hunger > -maxHunger)
    38.             Die();
    39.  
    40.     }
    41.  
    42.  
    43.     public void Die()
    44.     {
    45.         print('You have died because thirst or hunger');
    46.     }
    47. }
    48.  
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    look at the error log.... the script didn't compile
     
  3. neyu_unity

    neyu_unity

    Joined:
    Jun 15, 2018
    Posts:
    6
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  5. neyu_unity

    neyu_unity

    Joined:
    Jun 15, 2018
    Posts:
    6
    i got this error : error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
     
  6. neyu_unity

    neyu_unity

    Joined:
    Jun 15, 2018
    Posts:
    6
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
    You need to fix all compiler errors, double click on the errors in the console and fix the errors so that your scrips compile. If you need help, post the error and the line of code where the error happens so we can make suggestions on how to fix them.

    You have a bunch of errors in that script as well, for example:

    This is not a valid line of code.
     
  8. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    You have to rename the script asset to Player instead of player.
     
    Joe-Censored likes this.
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This ^^^

    All Monobehaviour scripts need a filename that matches the class name, and these are case sensitive. "Player" and "player" are not the same.

    Also, just a little pet peeve, but when referring to computer code the word "code" is already plural. No need to add an "s" to the end :p
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    These are not valid syntax:

    thirst + -thirstIncreaseRate * Time.deltaTime;

    health - maxHealth;

    You are missing the = signs!