Hi People, can someone tell if this correct to change color via script is correct? Thank you

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CambiaColoreFoglie : MonoBehaviour
{
    public GameObject prefabFoglie;
    private MeshRenderer meshFoglie;

    private void Start()
    {
        meshFoglie = prefabFoglie.GetComponent<MeshRenderer>();
    }

    public void CambiaFoglie()
    {
        meshFoglie.material.color = new Color(Random.value, Random.value, Random.value);
    }
}

I’m starting to think this is an organized DDOS attack or an AI training data gathering operation.

4 Likes

I haven’t been able to determine an upside to these posts but something is definitely up. They are related in subject, in title, the members all joined today less than an hour ago.

The snippets provided are massively meaningless.

No it’s not a DDos attack we study together for some exams. We are new on the platform and we have been using this forum to check our codes before the exams.

3 Likes

Then tell your mates that you can answer your own questions by testing your own code. It’s Unity! You can just into play mode and see if it works within seconds. Don’t need to ask us. And what we think is ‘correct’ could be completely different to what the testers grade on you.

IF you have a problem, then that is a good reason to make a thread asking for help AFTER you have debugged and researched the problem thoroughly yourself.

That said, there is a ‘gotcha’ when it comes to the .material property of renderer components, but I’ll let you read about that yourself in the documentation: Unity - Scripting API: Renderer.material

2 Likes