public void CopyFrom(Player player) { bullet = player.bullet; bulletSpeed = player.bulletSpeed; cooldown = player.cooldown; movementSound = player.movementSound; Rigidbody2D body = GetComponent<Rigidbody2D> (); Rigidbody2D playerBody = player.GetComponent<Rigidbody2D> (); body.mass = playerBody.mass; body.angularDrag = playerBody.angularDrag; body.drag = playerBody.drag; }
public void PlayerChangeMainBody(Player player) { Debug.Log ("---Changing main body"); GameObject[] gameObjects = GameObject.FindGameObjectsWithTag (Constants.TAG_PLAYER); if (gameObjects != null && gameObjects.Length > 0) { int maxJoints = 0; GameObject maxJointsObject = null; foreach (GameObject obj in gameObjects) { if (!obj.name.Equals ("Player")) { if (maxJointsObject == null) { maxJointsObject = obj; } else { Joint2D[] joints = obj.GetComponents<Joint2D> (); if (joints != null && joints.Length > maxJoints) { maxJoints = joints.Length; maxJointsObject = obj; } } } } if (maxJointsObject != null) { maxJointsObject.name = "Player"; maxJointsObject.tag = Constants.TAG_CURRENT_PLAYER; Destroy (maxJointsObject.gameObject.GetComponent<Pickup> ()); Transform newEye = (Transform)Instantiate (eye, maxJointsObject.transform.TransformPoint (eye.transform.localPosition), maxJointsObject.transform.rotation); newEye.gameObject.SetActive (true); newEye.parent = maxJointsObject.transform; Player newPlayer = maxJointsObject.GetComponent<Player> (); newPlayer.enabled = true; newPlayer.CopyFrom (player); return; } } Debug.Log ("Couldn't find another body"); GameOver (); Destroy (player); }