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. Dismiss Notice

UnityEngine.Time.deltaTime is a property access but a type was expected

Discussion in 'Scripting' started by jasmindelacruz, Jul 5, 2014.

  1. jasmindelacruz

    jasmindelacruz

    Joined:
    Jun 25, 2014
    Posts:
    30
    Code (CSharp):
    1.  
    2.  
    3.  
    4.  
    5. using UnityEngine;
    6. using System.Collections;
    7. using UnityEngine.Time.deltaTime;
    8.  
    9. public class Tap : MonoBehaviour
    10. {
    11.     public Texture2D buttonImage = null;
    12.     public GameObject objectToMove;
    13.    
    14.     private float timer;
    15.    
    16.     void Start()
    17.     {
    18.         timer = 0.0f;
    19.     }
    20.    
    21.     void Update()
    22.     {
    23.         timer += Time.deltaTime;
    24.     }
    25.    
    26.     private  void OnGUI()
    27.     {
    28.         if (timer > 3.0f)
    29.         {
    30.             if (GUI.Button (new Rect(50,350,300,100),buttonImage))
    31.             {
    32.                 this.transform.position += new Vector3(-1.0f, 0.0f, 0.0f) ;
    33.             }
    34.         }
    35.     }
    36. }
    37.  
     
  2. earrgames

    earrgames

    Joined:
    Jan 27, 2014
    Posts:
    168
    Hi! you don't need to import "using UnityEngine.Time.deltaTime;" just with importing "using UnityEngine" it contains the definition for time. Remove that third line and you're done.

    Cheers!
     
  3. jasmindelacruz

    jasmindelacruz

    Joined:
    Jun 25, 2014
    Posts:
    30

    i already removed it... but thre's still an error "Time does not contain a definition for deltatime"
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Rename your Time class to something else, ideally.

    --Eric
     
  5. Kieran Chandler

    Kieran Chandler

    Joined:
    Sep 29, 2011
    Posts:
    116
    If you want to keep your time class, you will have to refer to the unityengine time class as UnityEngine.Time.deltaTime

    Code (CSharp):
    1. float number = UnityEngine.Time.deltaTime;

    so whenever you want to use it you put "UnityEngine." in front of it. The best option though, would be to follow Eric5h5's advice to avoid further confusion down the line