There is no Renderer attached to the MainCharacter game object
Okay, so I need help with an issue. I want my main character in a third person shooter game to have a random color every time the game starts. I also want the enemies to have a completely random color. Everyone shoots a prefab projectile which should also have a completely random color.
I've found a simple script which in my noob ways I think it meets my needs. I've tried attaching it to my main character but when I hit play I get this error "MissingComponentException: There is no 'Renderer' attached to the "MainCharacter" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "MainCharacter". Or your script needs to check if the component is attached before using it. ColorChanger.RandomColor () (at Assets/Scripts/ColorChanger.cs:10) "
What do I do now? Any help is much appreciated. This is the script: using UnityEngine; using System.Collections;
public class ColorChanger : MonoBehaviour {
void Start() {
RandomColor();
}
public void RandomColor() {
GetComponent<Renderer>().material.color = new Color(Random.value, Random.value, Random.value);
}
}
Your answer
Follow this Question
Related Questions
How to only access one object in array if it's index is 1 0 Answers
how can i access list of sprites in my code ?? 0 Answers
How to generate a random color? 5 Answers
Material darker in inspector then scene? 0 Answers
How to make RANDOM COLOR on shader 1 Answer