- Home /
How to make incorporate a function and a loop
[SerializedField] Material[] materials = new Material[2]; Renderer_renderer;
private void Awake()
{
_renderer = GetComponent<Renderer>()
_renderer.sharedMaterial = materials[0];
}
private void OnCollisisonEnter(Collision collision)
{
if (collision.collider.CompareTag("User"))
_renderer.sharedMaterial = materials[1];
}
private void OnCollisionEnter(Collisison collision)
{
}
void Color private void OnCanvasGroupChanged()
{
void ColorChange()
}
{
Renderer renderer = GetComponent<Renderer>();
//changes the colour to purple
renderer.material.shader = Shader.Find("_Color");
renderer.material.SetColor("_Color", Color.purple);
//changes the colour to red
renderer.material.shader = Shader.Find("Specular");
renderer.material.SetColor("_SpecColor", Colour.red);
//chnages the color to yellow
renderer.material.shader = Shader.Find("_Color");
renderer.material.SetColor("_Color", Color.yellow);
//changes the color to cyan
renderer.material.shader = Shader.Find("Specular");
renderer.material.SetColor("_SpecColor", Color.cyan);
How can I add a function (not a built-in function) into my code?
Please be more specific on your question. What function do you want to implement? What difficulty you are facing now?
Answer by ShadyProductions · Sep 26, 2018 at 07:48 AM
Just make one?
public void ThisIsOneIMade() {
//Code to execute
}
then u can call it like
ThisIsOneIMade();
anywhere u want in another function
This is basic C#..
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods
Answer by viknesh2020 · Sep 26, 2018 at 09:43 AM
I think you missing something.
void Color private void OnCanvasGroupChanged() *//I am not sure what are you talking about here*
{
ColorChange(); *//Remove void here and put a semicolon at the end.*
}
public void ColorChange() {
Renderer renderer = GetComponent<Renderer>();
//changes the colour to purple
renderer.material.shader = Shader.Find("_Color");
renderer.material.SetColor("_Color", Color.purple);
//changes the colour to red
renderer.material.shader = Shader.Find("Specular");
renderer.material.SetColor("_SpecColor", Colour.red);
//chnages the color to yellow
renderer.material.shader = Shader.Find("_Color");
renderer.material.SetColor("_Color", Color.yellow);
//changes the color to cyan
renderer.material.shader = Shader.Find("Specular");
renderer.material.SetColor("_SpecColor", Color.cyan);
} *//You missed a basic syntax of a function*
Your answer

Follow this Question
Related Questions
Loop a function in c#.HELP!!! 2 Answers
Loop a function 1 Answer
while loop not looping 2 Answers
first function dismiss 0 Answers
Loop a Function a Random Number of Times 2 Answers