generate a c# unity script to create 10 cubes spread out by 1 unit on the x axis with…
- User
generate a c# unity script to create 10 cubes spread out by 1 unit on the x axis with the material colour changing between the first and last from green to red
Assistant
Here is a C# Unity script that will generate 10 cubes spread out by 1 unit on the x axis with the material colour changing from green to red:
using UnityEngine; public class GenerateCubes : MonoBehaviour { void Start () { for (int i = 0; i < 10; i++) { // Create cube gameObject GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); // Position on x axis 1 unit apart cube.transform.position = new Vector3(i, 0, 0); // Set scale cube.transform.localScale = new Vector3(1,1,1); // Create material Material mat = new Material(Shader.Find("Diffuse")); // Change from green to red float r = i/10f; mat.color = Color.Lerp(Color.green, Color.red, r); // Assign material to cube cube.GetComponent<MeshRenderer>().material = mat; } } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.