public void NewColor() { // Build list of available colors HashSet <Color> colors = new HashSet <Color>(); foreach (var food in FindObjectsOfType <Food>()) { colors.Add(food.c); } // Remove current color, to make sure the color always changes Color current = GetComponent <Renderer>().material.color; colors.Remove(current); // Check if color change is available if (colors.Count == 0) { return; } // Change to a random color Color newColor = colors.ElementAt(Random.Range(0, colors.Count)); GetComponent <Renderer>().material.color = newColor; successor.SetColor(newColor); }
public void SetColor(Color c) { GetComponent <Renderer>().material.color = c; if (successor) { successor.SetColor(c); } }
public void AddTail(FollowPredecessor newTailBit) { if (successor) { successor.AddTail(newTailBit); return; } Vector3 dir = Vector3.Normalize(location.Value - location.Previous.Value); ExtendPath(dir); successor = newTailBit; successor.location = location.List.Last; successor.transform.position = successor.location.Value; successor.predecessor = this; successor.SetColor(GetComponent <Renderer>().material.color); }