I'm trying to learn how to debug in unity, and at the moment i'm using this code to find factorials.
using UnityEngine;
using System.Collections;
public class CodeExample : MonoBehaviour {
// Use this for initialization
void Awake()
{
print (Fac (-1));
print (Fac (0));
print (Fac (5));
}
int Fac(int n)
{
if (n<0)
{
return (0);
}
if (n==0)
{
return(1);
}
int result = n* Fac(n-1);
return(result);
}
While debugging, i've put the integer "result" on watch, so i can see it's changes as the Awake class iterates through the Fac() function multiple times. However when i use step into on Fac(5), result keeps staying at zero, and once Fac(5) gets to "return(result)", result is said to be 1.
However in unity it shows me 120 as the answer. So i'm just curious, how can i keep an eye on the result integer, so i can watch it's change throughout the code?
Any help is greatly appreciated :)
↧