No scripts are running. C#

When I click, it should be picked up (Update function) but it isn’t.
I’ve added debugs to test, to no avail.

        if(Input.GetMouseButtonDown(0))
        {}

Any help is appreciated.

Post more code.

Does the script inherit from MonoBehaviour? Is Update spelled correctly? Is the script attached to some GameObject in the scene? Is that GameObject active?

  1. Yes
  2. Yes
  3. Yes
  4. Yes
    void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            Debug.Log ("Clicked");
            if(Physics.Raycast(ray, out hit, 100))
            {
                if (hit.transform.gameObject.tag == "Clickable")
                {
                    Debug.Log ("Hit");
                    TileInformationScript tis = hit.transform.gameObject.GetComponent<TileInformationScript> ();
                    ClickGUI clickGUI = new ClickGUI (tis.name, tis.briefDescription, tis.cost);
                    clickGUI.generateTooltip ();
                    clickGUI.toggleActive ();
                }
            }
        }
    }

After further testing, I have found that the script itself isn’t running. I tried implementing a Start method to no avail.

Anyone know what the problem is?

Hierarchy: Screenshot - fe5832bfb6e2c92340ffaf1521af9bc6 - Gyazo

EDIT: Tried recreating the script, tried putting it in a new scene, it’s still not working.

Maybe Unity’s not recompiling when you change the script; did you turn off automatic recompiling in the editor settings? Try right-clicking the script in the project window and choose Reimport.

https://gyazo.com/265aa2668359dbdf9a53e7be0ae703dd ?

I tried reimport. No avail.

I put this in empty gameobject and it works just fine. Using Visual Studio btw, not MonoDevelop.

using UnityEngine;

public class ClickInformation : MonoBehaviour {
   
    void Start () {
        Debug.Log("Started");
    }
   
    void Update () {
        if (Input.GetMouseButtonDown(0)) {
            Debug.Log("Clicked");
        }
    }
}

I think I’ll try recreating the project.

EDIT: Made a completely blank project, added a quick script to print a debug. Nothing prints.

EDIT: Tried exporting, still doesn’t work.

I do not at all understand this.

EDIT: It doesn’t run the script, AT ALL. And I have no idea why.

Is the filename Called ClickInformation.cs and your class ClickInformation Those two names have to be identical or unity won’t run the script. Though it should spit out a console error if this were the case.

I’ve tried recreating the script, reinstalling Unity, creating new projects, scenes, everything in the book but it just isn’t working.

Are none of your scripts working at all, or is it just this one? Did scripts used to work, or is this the first time you’re writing your own scripts?

I have written many scripts before but in different projects, they all worked fine.

For some reason, these ones don’t seem to be working.

The inspector shows the necessary public variables but the code doesn’t run.

Yeah that’s bizarre; I’ve never seen that happen. You should send a bug report to Unity with the sample project, maybe they’d have some answers.

Maybe upload the project to github or oneDrive and I can open it and see what happens

Have done, waiting for a reply.

I’ll try and do it sometime tomorrow.

Could you play the project, and post a screenshot of the console window?

Nothing is shown, but here it is anyway.
https://gyazo.com/f533b58337b630272d9ed1b0367eec4b
Oh…

That was a stupid error from me. I’ve just realised I had debugs off?? For goodness sake…
So sorry everyone, I feel like I’ve wasted your time.
Rookie mistake.

Unrelated - you can put images right in your post without having to host them somewhere else. Then users don’t need to click a link to see what you’re talking about.

They often don’t work with gyazo links so I didn’t assume that would work, thanks though.

You can just upload directly from your machine.