Snake Movement unity (Snake vs Block) HELP!!!!!

public class PallinaMovement : MonoBehaviour {

public float pallinaSpeedX;
public float pallinaSpeedY;

//punto finale dello schermo cliccato
public Vector3 endPos;
public Vector3 startPos;

public static PallinaMovement pallinaMovement;

GameObject particles;

void Awake(){

if (pallinaMovement == null) {

pallinaMovement = this;
}
}

void Start () {

SalvataggioNUOVO.control.Load ();
pallinaSpeedX = 3.0f;
pallinaSpeedY = 0.05f;
}

void FixedUpdate () {

if (SalvataggioNUOVO.control.isAccelerometerEnable == false) {

TouchAxisMove();
}

if (SalvataggioNUOVO.control.isAccelerometerEnable == true) {

AccelerometerMove ();
}
}

void AccelerometerMove(){
pallinaSpeedX = 5;

float x = Input.acceleration.x;

if (x < -0.1f) {

MoveLeft ();

} else if (x > 0.1f) {

MoveRight ();

} else {

SetVelocityZero ();
}
}

void TouchMove()
{ pallinaSpeedX = 3;

if (Input.touchCount >= 1)
{

Touch touch = Input.GetTouch(0);

float middle = Screen.width / 2;

if (touch.position.x < middle)
{
MoveLeft();
}
else if (touch.position.x > middle)
{
MoveRight();
}

}else{

SetVelocityZero();
}

}

void TouchAxisMove(){

pallinaSpeedX = 3f;

if (Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Began) {

startPos = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetTouch (0).position.x, 0, 0));
SetVelocityZero ();
}

if(Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Moved){

endPos = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetTouch (0).position.x, 0, 0));

float a = (endPos.x - startPos.x);

gameObject.transform.position += new Vector3(a/50 ,pallinaSpeedY,0);

ManageGame.manageGame.isMoving = true;

} else {

ManageGame.manageGame.isMoving = false;
SetVelocityZero ();
}

}

public void MoveLeft()
{
gameObject.transform.position += new Vector3(-0.03f,pallinaSpeedY,0);
}

public void MoveRight()
{
gameObject.transform.position += new Vector3(0.03f,pallinaSpeedY,0);
}

public void SetVelocityZero()
{
gameObject.transform.position += new Vector3(0,pallinaSpeedY,0);
}

void OnCollisionEnter2D(Collision2D coll){

if (coll.gameObject.tag == “RomboNormale”) {

SalvataggioNUOVO.control.monete += 1;
SalvataggioNUOVO.control.Save ();

ManageGame.manageGame.moneteGameplay.text = SalvataggioNUOVO.control.monete.ToString ();

ManageGame.manageGame.romboEffettoCoins.gameObject.SetActive (true);
ManageGame.manageGame.romboSpecialeEffettoCoins.gameObject.SetActive (false);

Invoke (“Disable”, 1.5f);

Destroy (coll.gameObject);
}

if (coll.gameObject.tag == “RomboSpeciale”) {

SalvataggioNUOVO.control.monete += 10;
SalvataggioNUOVO.control.Save ();

ManageGame.manageGame.romboSpecialeEffettoCoins.gameObject.SetActive (true);
ManageGame.manageGame.romboEffettoCoins.gameObject.SetActive (false);

Invoke (“Disable”, 1.5f);

Destroy (coll.gameObject);
}
}

public void Disable(){

ManageGame.manageGame.romboSpecialeEffettoCoins.gameObject.SetActive (false);
ManageGame.manageGame.romboEffettoCoins.gameObject.SetActive (false);
}
}

Hey, on the bottom left of your own post, there is an option called “EDIT”.
Use that option to modify your post a bit :

  • First, copy all the code, then click on the button looking like a newspaper page, select code. Then , paste the code inside the box that just opened. It will be 10 times easier for poeple to read your code (even more if your code is long).
  • Then, try to explain: What is the problem? What is the behaviour you would like to have, and how is it different from what you actually have ?
1 Like