Hello, I’m making slither.io mobile in unity 3d and my joystick controls don’t work. The snake only moves left and right. I want it to follow the direction the joystick is pointing. Help me please.
Please write very clearly as I am new to this. And sorry for my bad english. I hope, you understood me
My script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SnakeMovement : MonoBehaviour
{
public float Speed;
public float RotationSpeed;
public List tailObjects = new List();
public float z_offset = 0.5f;
public GameObject TailPrefab;
public Text ScoreText;
public int score = 0;
public Joystick joystick;
void Start()
{
tailObjects.Add(gameObject);
}
void Update()
{
ScoreText.text = score.ToString();
transform.Translate(Vector3.forward*Speed*Time.deltaTime);
Vector3 direction1 = Vector3.up*joystick.Horizontal;
transform.Rotate(direction1*RotationSpeed*Time.deltaTime);
}
public void AddTail()
{
score++;
Vector3 newTailPos = tailObjects[tailObjects.Count-1].transform.position;
newTailPos.z -= z_offset;
tailObjects.Add(GameObject.Instantiate(TailPrefab,newTailPos,Quaternion.identity) as GameObject);
}
}