public void Play() { State = lvlState.Play; SwipeControl.ResetFp(); SwipeControl.BlockSwipeInput(); StartPage.SetActive(false); }
void FixedUpdate() { if (!IsInGame()) { var map = GetComponentInParent <MapData>(); SwipeControl.BlockSwipeInput(); map.player = Instantiate(map.PlayerPrafab, map.PlayerPos, Quaternion.Euler(startEuler), map.transform); if (DoneBlockCount != 0) { map.player.GetComponent <PlayerControl>().DoneBlockCount = DoneBlockCount; } Destroy(this.gameObject); } velocity = GetComponent <Rigidbody2D>().velocity; if (velocity.magnitude < speed / 1000 || velocity.magnitude > speed * 2f) { velocity = Vector2.zero; } else { ChangeFactor(GetDistance(viewDir)); } if (Mathf.Abs(velocity.x) > Mathf.Abs(velocity.y)) { velocity.y = 0; } if (Mathf.Abs(velocity.y) > Mathf.Abs(velocity.x)) { velocity.x = 0; } if (preVelocity != 0 && velocity.magnitude == 0 && SwipeControl.AllowSwipes) { RotationSkin.Find("playerscaler").GetComponent <Animator>().SetTrigger("hited"); // ps.loop=false; var ps = CarParticles.transform.Find("FX_DirtSplatter").GetComponent <ParticleSystem>().emission; ps.enabled = false; // CarParticles.transform.Find("FX_DirtSplatter").GetComponent<ParticleSystem>().enableEmission = false; // CarParticles.transform.Find("FX_DirtSplatter").GetComponent<ParticleSystem>().Stop(); Vibration.Vibrate(VibroMillis); } preVelocity = velocity.magnitude; if (velocity.magnitude > 0) { SwipeControl.ResetFp(); // SwipeControl.BlockSwipeInput(); UpdateVelocity(viewDir); GetComponent <Rigidbody2D>().velocity = velocity; return; } preViewDir = viewDir; if (Input.GetKeyDown("w") || SwipeControl.GetUpSwipe()) { viewDir = Vector2.up; // RotationSkin.eulerAngles= Vector3.forward*90; } if (Input.GetKeyDown("s") || SwipeControl.GetDownSwipe()) { viewDir = Vector2.down; // RotationSkin.eulerAngles= Vector3.forward*(-90); } if (Input.GetKeyDown("a") || SwipeControl.GetLeftSwipe()) { viewDir = Vector2.left; // RotationSkin.eulerAngles= Vector3.forward*180; } if (Input.GetKeyDown("d") || SwipeControl.GetRightSwipe()) { viewDir = Vector2.right; // RotationSkin.eulerAngles= Vector3.zero; } if (velocity.normalized != viewDir) { RotationSkin.eulerAngles = GetEulerToAlign(); // Debug.Log(RotationSkin.eulerAngles+" "+GetEulerToAlign()); // Debug.DrawRay(RotationSkin.position,viewDir*10,Color.red,10); SetVelocity(viewDir); } }