Primitive colors and materials
After endless hours scouring the internet, I have given up and am here to ask this question. I am trying to spawn a bunch of primitive, and then either apply a material from my Assets folders, or just directly apply a color. Below is my code and the comments are a bunch of snippets from different tutorials and forum answers. None of these have worked for me so far. How do I do this?
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class SpawnSpheres : MonoBehaviour
{ void Start() { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = new Vector3(0, 0, 0); sphere.transform.localScale = new Vector3(2, 2, 2);
// public Color32 color32 = new Color32(64, 128, 192, 255);
// Material redMat = Resources.Load("red", typeof(Material)) as Material;
// Renderer rend = sphere.GetComponent<Renderer>();
// rend.material.mainTexture = redMat;
// Material myMaterial = Resources.Load("Materials/yellow");
// sphere.material.SetColor
// sphere.renderer.material.color
} }
Comment