void Start() { mainSnake = GameObject.FindGameObjectWithTag("SnakeMain").GetComponent <SnakeMovment>(); Speed = mainSnake.Speed; tailTargetObj = mainSnake.tailObjects[mainSnake.tailObjects.Count - 2]; indx = mainSnake.tailObjects.IndexOf(gameObject); }
void Awake() { //mainSnake = tailTargetObj.GetComponent<SnakeMovment>(); mainSnake = GameObject.FindGameObjectWithTag("player").GetComponent <SnakeMovment>(); tailTargetObj = mainSnake.tailObjects[mainSnake.tailObjects.Count - 1]; gameObject.GetComponentInChildren <Renderer>().material.color = mainSnake.gameObject.GetComponentInChildren <Renderer>().material.color; }
void Start() { mainSnake = GameObject.FindGameObjectWithTag("SnakeMain").GetComponent <SnakeMovment>(); // Magic numbers aren't good style, make it by multiplying on a variable // 2.5f should be a variable like float speedMultiplier // And one more thing. What would you do if snake speed change? Look for Observer pattern Speed = mainSnake.Speed + 2.5f; // Actually not the best solution. I've understood what you want to do, but we can write a function GetTailTarget() or // smth similar. And I don't get why you get link to the snake head. As for me, better to get link to the last tail obj // and move toward it tailTargetObj = mainSnake.tailObjects[mainSnake.tailObjects.Count - 2]; indx = mainSnake.tailObjects.IndexOf(gameObject); }