BrettM
5/21/2019 - 2:27 AM

[Beginner] Methods/Fucntions

public int a = 5;
public int b = 5;

public int total;

public GameObject cube;

void Update()
{
  if (Input.GetKeyDown(KeyCode.Space))
  {
    //Function #1
    TellMeThePosition(this.gameObject, "Hey there!");
    
    //Function #2, pass in multiplier
    total = Multiply (a, b);
    Debug.Log("Total: " + total);
    
    //Function #3, color function
    cube.GetCompent<Renderer>().material.color = ChangeColor(Color.red, cube, "Jon");
  }
}

public int Multiply (int a, int b)
{
  return a * b;
}

void TellMeThePosition (GameObject go, string message)
{
  Debug.Log("Position " + go.transform.position + "      " + message)
}

Color ChangeColor(Color newColor, GameObject go, string name)
{
  go.name = name;
  return newColor;
}