Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

error CS0103: The name 'time' does not exist in the current context

Discussion in 'Scripting' started by MariuscoGames, Jan 4, 2022.

  1. MariuscoGames

    MariuscoGames

    Joined:
    May 21, 2020
    Posts:
    34
    Hello. I am making a game in unity 2020.3.0 and this error has appeared:
    Assets\Scripts\Assembly-CSharp\EventScript.cs(19,25): error CS0103: The name 'time' does not exist in the current context

    This is my script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EventScript : MonoBehaviour
    6.  
    7. {
    8.        // Timer function
    9.     public void Start()
    10.     {
    11.         this.eventTime = UnityEngine.Random.Range(100, 300);
    12.     }
    13.  
    14.     // Repeating timer
    15.     public void Update()
    16.     {
    17.         if (  this.eventTime > 0  )
    18.     {
    19.         this.eventTime -= 1 * time.DeltaTime;
    20.     }
    21.     else
    22.     {
    23.     this.eventType = UnityEngine.Random.Range(0f, (2 - 1) );
    24.     }
    25.     if (this.eventType == 0f)
    26.     {
    27.     //Event 1 code here
    28.     }
    29.     else if (this.eventType == 1f)
    30.     {
    31.     //Event 2 code here
    32.     }
    33. }
    34.  
    35.     // The waitng time before an event
    36.     public float eventTime;
    37.  
    38.     // The event type
    39.     public float eventType;
    40. }
    41.  
    What have I done wrong?
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    Code is case sensitive. It's Time, not time.
     
    MariuscoGames likes this.
  3. MariuscoGames

    MariuscoGames

    Joined:
    May 21, 2020
    Posts:
    34
    Like this?
    Code (CSharp):
    1. this.eventTime -= 1 * Time.DeltaTime;
     
  4. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    Sorry, I didn't notice you had another error. The correct format is
    Time.deltaTime
    , Time is capitalized, and deltaTime is not.

    Here's reference.
     
  5. MariuscoGames

    MariuscoGames

    Joined:
    May 21, 2020
    Posts:
    34
    Ok, now has no error. Thanks