Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If I change the word Update in void update, my character no longer jumps. I was just wondering, why? It makes me feel like that whenever I try to create a new class in the future, it might not work simply because it's not in void Update. I don't understand. I've seen scripts not have void Update before. So what's the difference? Can someone explain please? Thanks.



C#
using UnityEngine;
using System.Collections;

public class tulMoving : MonoBehaviour {
    public float moveSpeed;
    public float jumpHeight;

    void Start ()
    {

    }

    void Update ()
    {
        if (Input.GetKeyDown (KeyCode.Space))
            GetComponent<Rigidbody2D>().velocity = new Vector2(0, jumpHeight);
    }
}
Posted
Updated 4-Nov-15 6:22am
v8
Comments
Suvendu Shekhar Giri 4-Nov-15 2:04am    
not clear enough.
[no name] 4-Nov-15 10:16am    
how so?
Foothill 4-Nov-15 10:45am    
Is this a Unity engine script?
[no name] 4-Nov-15 12:13pm    
yes its updated now.
Richard MacCutchan 4-Nov-15 12:20pm    
That's hardly surprising. If some part of your code makes a call to Update but there is no method with that name then it will not work. In fact it should not even compile.

There no possible solution to your question the way you ask it.
Look at the snipset of code you provided ! It is a joke !

You don't show what update() is doing, and you don't show what you do with is. This and nothing is the same.

[update]
By removing theses 3 little lines that are everywhere in your code but not on our screen, you removed the context, making the published code meaningless. This is what make it a joke !

In C# a function name, after compilation, is composed of the name + parameters + return type. By changing the return type, your library can't find the 'new' function because the library is still looking for the old function.

It is even possible that your library embed a dummy update function that does nothing and is used when the user don't provide one.
 
Share this answer
 
v3
Comments
[no name] 4-Nov-15 10:16am    
well the only thing that isn't included is...
------------------------------------------------------------
using UnityEngine;
using System.Collections;

public class tulMoving : MonoBehaviour {
------------------------------------------------------------

which is at the start of every code, along with the two ending curly brackets.

Also, I wouldn't go around insulting people asking a question and trying to learn because it just makes you look bad, and it just makes people not want to listen to you. So if anything here is a joke, it's you.

I didn't put it in because that part of the code, with the exception of the name of the public class, is at the start of every c# code, so I thought it was unnecessary. And yes, it works unless you change Update in void Update. So if I change it to let's say, void Jump, it won't work anymore. And I don't see how my code is even relevant since it's more of a general question to begin with, about void Update.

also, the character is jumping. that's the end of the code. Again - i just forgot to throw in the curly brackets. so apologies there
Richard Deeming 4-Nov-15 11:36am    
Those lines might be at the top of every code file you have, but they're not at the top of every single code file ever produced.

Without them, there is no way to know what your base class is, and no way for anyone to know what your code is doing.

Remember, we cannot see your screen, access your computer, or read your mind. If you don't tell us what your code is trying to do, there's no way we can know.

Update your question with the full code, and someone who knows Unity might be able to answer it.
[no name] 4-Nov-15 12:13pm    
there
Richard Deeming 4-Nov-15 12:14pm    
OK, now you just need to wrap the code block in <pre>...</pre> tags so that it's formatted properly. :)
Patrice T 4-Nov-15 15:04pm    
May be a little rude, but no insult here, insult s are reserved to "DoMyHomeWork" and "DoMyJob" questions where the biggest effort was to verbatim the problem.

Apologies accepted, I guess next time you will give all details, and you will see that answers are not the same :)
I'm not familiar with Unity, but the documentation[^] says that the Update method is "called every frame, if the MonoBehaviour is enabled".

That suggests that something within Unity is specifically looking for a method called Update on your behaviour. If you call the method something else, it won't be called, because Unity doesn't know about it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900