Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Public variables not showing in Inspector

Discussion in 'Scripting' started by unity_C344DB5470DEE7ECD137, Jul 14, 2021.

  1. unity_C344DB5470DEE7ECD137

    unity_C344DB5470DEE7ECD137

    Joined:
    Jul 3, 2021
    Posts:
    8
    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public class Elevator : MonoBehaviour
    8. {
    9.     private bool moveup == true;
    10.     private bool movdown == false;
    11.     public transform up1, down1;
    12.     public float speed = 1;
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.  
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         if (movup == true, movdown == false)
    24.             {
    25.             transform.position = Vector3.MoveTowards(transform.position, up1.position, speed * Time.deltaTime);
    26.         }
    27.  
    28.         if (movup == false, movdown == true)
    29.             {
    30.             transform.position = Vector3.MoveTowards(transform.position, down1.position, -speed * Time.deltaTime);
    31.         }
    32.     }
    33.  
    34.     voidOnTriggerEnter(Collider other)
    35.     {
    36.         if (other.CompareTag("up"))
    37.         {
    38.             moveup = false;
    39.             movdown = true;
    40.         }
    41.         if (other.CompareTag("down"))
    42.         {
    43.             movdown = false;
    44.             moveup = true;
    45.         }
    46.     }
    47. }
    48.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    Probably because you've got a compiler error which you are ignoring. Note that you also didn't say that here.

    The compiler will tell you this is wrong.
     
  3. unity_C344DB5470DEE7ECD137

    unity_C344DB5470DEE7ECD137

    Joined:
    Jul 3, 2021
    Posts:
    8
    I got these errors in compiler.

    Assets\Elevator.cs(9,25): error CS1003: Syntax error, ',' expected
    Assets\Elevator.cs(10,26): error CS1003: Syntax error, ',' expected
    Assets\Elevator.cs(22,26): error CS1026: ) expected
    Assets\Elevator.cs(22,26): error CS1525: Invalid expression term ','
    Assets\Elevator.cs(22,26): error CS1002: ; expected
    Assets\Elevator.cs(22,26): error CS1513: } expected
    Assets\Elevator.cs(22,44): error CS1002: ; expected
    Assets\Elevator.cs(22,44): error CS1513: } expected
    Assets\Elevator.cs(27,27): error CS1026: ) expected
    Assets\Elevator.cs(27,27): error CS1525: Invalid expression term ','
    Assets\Elevator.cs(27,27): error CS1002: ; expected
    Assets\Elevator.cs(27,27): error CS1513: } expected
    Assets\Elevator.cs(27,44): error CS1002: ; expected
    Assets\Elevator.cs(27,44): error CS1513: } expected
    Assets\Elevator.cs(33,40): error CS1001: Identifier expected
    Assets\Elevator.cs(33,40): error CS1003: Syntax error, ',' expected
    Assets\Elevator.cs(33,44): error CS1031: Type expected
    Assets\Elevator.cs(33,44): error CS1001: Identifier expected
    Assets\Elevator.cs(37,21): error CS1002: ; expected
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    Yes because your code is wrong. Are you new to C# because the issues are really obvious?
    "==" is not assignment, it's comparing values. The correct operator is "=" for assignment.

    Even if you don't understand C# you should be able to see that you've missed the space after "void" and the method name "OnTriggerEnter".
     
  5. unity_C344DB5470DEE7ECD137

    unity_C344DB5470DEE7ECD137

    Joined:
    Jul 3, 2021
    Posts:
    8
    Yes, I am just starting out in C# and Unity. I fixed most of the errors and here is the code.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Elevator : MonoBehaviour
    7. {
    8.     public float speed = 1.5f;
    9.     public Transform up1, down1;
    10.     private bool movup = true;
    11.  
    12.     void Start()
    13.     {
    14.  
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         if(movup==true)
    20.         {
    21.             transform.position = Vector3.MoveTowards(transform.position, up1.position, speed * time.deltaTime);
    22.         }
    23.  
    24.         if (movup == false)
    25.         {
    26.             transform.position = Vector3.MoveTowards(transform.position, down1.position, -speed * time.deltaTime);
    27.         }
    28.     }
    29.  
    30.     void OnTriggerEnter(Collider other)
    31.     {
    32.         if(other.CompareTag("up"))
    33.         {
    34.             movup = false;
    35.         }
    36.  
    37.         if(other.CompareTag("down"))
    38.         {
    39.             movup = true;
    40.         }
    41.     }
    42. }
    43.  
    But, I am getting these errors only -

    Assets\Scripts\Level 1\Elevator.cs(20,96): error CS0103: The name 'time' does not exist in the current context
    Assets\Scripts\Level 1\Elevator.cs(25,99): error CS0103: The name 'time' does not exist in the current context

    Please help.
     
  6. unity_C344DB5470DEE7ECD137

    unity_C344DB5470DEE7ECD137

    Joined:
    Jul 3, 2021
    Posts:
    8
    fixed it. T should be capital.
    Thank you sir for helping me out.
     
    MelvMay likes this.