// Update is called once per frame void Update() { float HorDir = Input.GetAxisRaw("Horizontal"); float VerDir = Input.GetAxisRaw("Vertical"); if (HorDir == 1 && (Direction != PlayerDirection.RIGHT && Direction != PlayerDirection.LEFT)) { Direction = PlayerDirection.RIGHT; } else if (HorDir == -1 && (Direction != PlayerDirection.RIGHT && Direction != PlayerDirection.LEFT)) { Direction = PlayerDirection.LEFT; } if (VerDir == 1 && (Direction != PlayerDirection.UP && Direction != PlayerDirection.DOWN)) { Direction = PlayerDirection.UP; } else if (VerDir == -1 && (Direction != PlayerDirection.UP && Direction != PlayerDirection.DOWN)) { Direction = PlayerDirection.DOWN; } TimePassed += Time.deltaTime; if (ShouldMove) { TimePassed = 0; Vector3 Old = transform.position; Move(); BodySegment.SignalToMove(Old); } }
public void SignalToMove(Vector3 New) { Vector3 Old = transform.position; transform.position = New; if (NextNode != null) { NextNode.SignalToMove(Old); } else if (NextNode == null && ShouldReproduce) { ShouldReproduce = false; GameObject GO = Instantiate(BodyPrefab, Old, Quaternion.identity); NextNode = GO.GetComponent <BodyScript>(); } }