user3558131
user3558131

Reputation: 113

Logging additional information with Debugger.Log call

I am trying to log more information about context using Debug.Log call in Unity, to debug code an EXP system into my unity game.

I tried to just pass all arguments similar to String.Format but as expected got errors like:

"No overload method 'Log' takes '3' arguments

How can I log additional details along with message?

Code:

void Main()
{
    XP xp = new XP(1300);
    Debug.Log("Our character starts at {0} xp and is level {1}.", 
       xp.GetCurrentXp(), xp.GetCurrentLevel());
    Debug.Log("Now, we add 2000 xp.");
    xp.AddXp(2000);
    Debug.Log("Now, our character has {0} xp and is level {1}.", 
       xp.GetCurrentXp(), xp.GetCurrentLevel());
    Debug.Log("Our character is {0}% in to his next level", 
       xp.GetPercentInToLevel() * 100f);
}

errors

Upvotes: 2

Views: 248

Answers (1)

Phenix_yu
Phenix_yu

Reputation: 304

Indeed Debug.Log only have overrides with 1 and 2 arguments (scripting API):

public static function Log(message: object): void;
public static function Log(message: object, context: Object): void; 

You may want to use String.Format to construct message:

Debug.Log(string.Format("Our character starts at {0} xp and is level {1}.", 
      xp.GetCurrentXp(), xp.GetCurrentLevel()));

Upvotes: 1

Related Questions