[SOLVED] the renderer object gone

Updated on March 2, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on February 20, 2018

hai…. i want to ask something about my coding… so basically i want to change an object material color from white to red… here the code… 




using System.Collections.Generic;
using UnityEngine;
public class slimeway : MonoBehaviour {
 public Animator slime;
 public Animator enemy;
 public Renderer eye1;
 Color colour = Color.white;
 float t = 0f;
void Start(){
 eye1 = GetComponent ();
 eye1.material.color = colour;
void Update(){
 t += Time.deltaTime / 5;
 if (Input.GetKeyDown (KeyCode.A)) {
 colour.r += t;
 eye1.material.color = clour;
 slime.SetTrigger ("angry");
 } else if (Input.GetKeyDown (KeyCode.S)) {
 slime.SetTrigger ("calm");
 } else if (Input.GetKeyDown (KeyCode.D)) {
 enemy.SetTrigger ("die");
 slime.SetTrigger ("die");




till the end everything is okay… but the problem appear when i play unity… the object on the eye1 variable is gone withou trace… can somebody tell me what happen and what should i do? thanks… oh here the sceren shot






  • Liked by
1 on February 20, 2018

It’s because you’re using GetComponent on an object that does not have a renderer component. Try using GetComponentInChildren, or just remove it and set it in the inspector like you already are.


on March 2, 2018

thanks… i got it

Show more replies
  • Liked by