简体   繁体   中英

GetMouseButtonDown unity c#SCRIPT not work when i click it

void update(){  
    if (Input.GetMouseButtonDown(0)){

     int randomNumber= Random.Range(0,ball.Length);
    Instantiate(ball[randomNumber], transform.position, Quaternion.identity);

    }

       }

hi, everyone, I'm a beginner when I press the mouse button on the scene in unity nothing appear(game object ) any suggestion?

So there might be a couple of things happening here.

Are there any error messages showing up? Also check your inspector, in the scene view in unity there's a list of all objects that are currently existing the object might be showing up but you just can't see it depending on where exactly transform.position is.

You could also have just not attached the script to an object it's a simple mistake but it happens.

C# is case sensitive and the Messages (I like to call them "magic methods", because they are called by the engine below the scripting layer) all have to be uppercase.

In your case this just means that Update needs to be written with a capital U at the beginning.


Just for a quick reference, here are all messages: Unity - Scripting API: MonoBehaviour

Also, because your code looks... unstructured, I suggest you should use some kind of auto-formatting (in Visual Studio you can do this in Edit->Advanced->Format Document ) and read the C# guidelines, so you are aware in how the language was intended to be written: C# Coding Converntions - C# Programming Guide | Microsoft Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM