Autorunning the script without attaching it to object

I don’t know if I missed a part of the video but I never saw any attaching of the Dropper.cs script in the video. Maybe this is down to me using a different version of unity but unless I put the Dropper.cs script on an object in the scene I don’t get anything in the console.

For reference I’m using Unity 2020.2.2f1

1 Like

Hi tobekko,

Welcome to our community! :slight_smile:

Thanks a lot for pointing this issue out. I’ve rewatched the video, and it seems you are right. I’m forwarding this issue to Rick.

Meanwhile, assign the component to the Inspector of your Cube game object by dragging and dropping the script onto the Inspector. Then you should be able to see the messages like Rick.

1 Like

I’ve rewatched the video as well and I’m thoroughly confused! It seems I forgot to attached the script to my cube… but it runs anyway - very interesting. I’ll poke around further to see what’s going on.

1 Like

@Rick just a heads up this is actually attached on the next video “If Statements”. I do agree its very odd it worked in this video, but maybe you used a pre template somehow or went back. Once it got attached in the next video it worked as a troubleshooting step you showed.

I’m not saying aliens, but aliens~

Yeah I did see it get attached in the next video, but was unsure if I had missed something.
This might have just been a mistake during video editing or something?

I keep getting an error of: ‘Time’ does not contain a definition for ‘deltaTime’. I have look at the document on Unity and can’t find out what I’m doing wrong. I’m using Unity 2020.1.17f personal. Also, I would like to add that my IDE is Visual Studio. Any help would greatly be appreciated. Here is my code is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Time : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    Debug.Log(Time.time);
}

}

1 Like

Hi! Welcome to the community!

You can open new threads to ask questions, you’ll get an answer a lot quicker if you do that.

The reason why you are getting that error is because, in fact, there’s no such thing as deltaTime in Time, let me explain further: Your class is named Time, there’s no such thing as deltaTime inside it, the UnityEngine Time class in the other hand does have a deltaTime definition.

Let me explain with an analogy: Imagine you are in a party looking for a guy named Scott, the guy has your watch, but there are two Scotts in the party, you are basically asking the wrong Scott, the one that doesn’t have your watch, to give you back your watch.

To solve your issue just rename your class in code and the file that is in your Assets Folder in Unity, use the same name.

//Instead of:
public class Time : MonoBehaviour

//Use another name, whichever you want
public class AnotherName : MonoBehaviour

Try to avoid using names that are already being used by any of the namespaces (UnityEngine, System.Collection) within your class to avoid this kind of situations.

There’s another solution, which is asking for Scott Pilgrim instead of simply Scott, but let’s stay for now with just changing your class’s name.

1 Like

Hi @Harry_Lott,

Is Visual Studio selected as your External Script Editor in Unity (Edit > Preferences > External Tools)?

I just added Visual Studio to Unity in the External Script Editor. Also, I applied the different “Class”, which Yee said to do, thanks, Yee! After the changes, the script worked. I would like to thank you for your time. I can’t wait to do more of this training.

I’m glad we were able to help. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms