//Stops the player from moving void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { CanMoveScript moveScript = collision.gameObject.GetComponent <CanMoveScript>(); moveScript.makeCannotMove(); } }
//Allows the player to move again void OnDestroy() { GameObject Player = GameObject.FindGameObjectWithTag("Player"); if (Player) { CanMoveScript canMoveScript = Player.gameObject.GetComponent <CanMoveScript> (); canMoveScript.makeCanMove(); } }
void FixedUpdate() { CanMoveScript canMoveScript = this.gameObject.GetComponent <CanMoveScript> (); if (canMoveScript.getMove()) { //Get the current position Vector3 pos = this.gameObject.transform.position; //Update the position for the next frame curSpeed = Speed; if (Input.GetAxis("Fire3") != 0) { curSpeed *= speedMultiplier; } pos.x = pos.x + (Input.GetAxis("Horizontal") * curSpeed); pos.y = pos.y + (Input.GetAxis("Vertical") * curSpeed); this.gameObject.transform.position = pos; } //Freeze the velocity this.GetComponent <Rigidbody2D> ().velocity = new Vector2(0, 0); }