// Use this for initialization void Awake() { _weaponAnimator = Weapon.GetComponent<Animator> (); _copAnimator = GetComponent<Animator> (); _weaponRotation = Weapon.GetComponent<PixelRotation> (); Angle = 0; }
// Use this for initialization void Awake() { bounceForce = 20f; time2Destroy = 3f; time2Reappear = .9f; flying = false; throwing = false; spearString = "Prefabs/Gear/Spear"; spearTipParentTransform = transform.GetChild(0); spearTipTransform = transform.GetChild(0).GetChild(0); spearTipCollider = spearTipTransform.GetComponent <CircleCollider2D> (); pixelRotationScript = GetComponent <PixelRotation> (); pixelRotationScript.Angle = 0; joyfulstickScript = GameObject.Find("StickHole").GetComponent <Joyfulstick> (); jaiScript = GameObject.Find("Jai").GetComponent <Jai> (); jaiTransform = jaiScript.transform; jaiScript.spearScript = GetComponent <Spear>(); joyfulstickScript.spearScript = GetComponent <Spear>(); stockPosition = transform.position - jaiTransform.position; throwAdjustmentVector = new Vector3[] { new Vector3(0f, .26f, 0f), new Vector3(0f, .31f, 0f) }; }
// Calculate the angle of the gun towards the mouse // This is only called on the local player void GunAngle(Transform arm, PixelRotation armRotation) { Vector3 screenPos = Camera.main.ScreenToWorldPoint (Input.mousePosition); bool shouldFlip = (facingRight && screenPos.x < transform.position.x || !facingRight && screenPos.x > transform.position.x); if (shouldFlip) Flip (!facingRight); Vector3 newAngles; if (facingRight) { // Rotate the parts newAngles = new Vector3 (0, 0, Mathf.Atan2 ((screenPos.y - arm.position.y), (screenPos.x - arm.position.x)) * Mathf.Rad2Deg); } else { // Rotate the parts newAngles = new Vector3 (0, 0, -Mathf.Atan2 (-(screenPos.y - arm.position.y), -(screenPos.x - arm.position.x)) * Mathf.Rad2Deg); } armRotation.Angle = (int) newAngles.z; // This sets the upper arm rotation the same as the weapon rotation PixelRotation upperArmRotation = LeftUpperArmRotation; if (armRotation == RightArmRotation) upperArmRotation = RightUpperArmRotation; upperArmRotation.Angle = armRotation.Angle; CmdSetAngle (armRotation.Angle, arm == RightArm); if (shouldFlip) CmdFlip (facingRight); }
// Sets all fields for the right arm public void ConfigureRightArm(Transform newRightArm) { RightArm = newRightArm; RightArm.parent = BodySprite.transform; RightArmSprite = RightArm.GetComponent<SpriteRenderer> (); RightArmRotation = RightArm.GetComponent<PixelRotation> (); RightArmWeapon = RightArm.GetComponent<Weapon> (); RightArmCanRotate = RightArmWeapon.CanRotate (); RightUpperArmRotation = RightUpperArm.GetComponent<PixelRotation> (); RightUpperArmSprite = RightUpperArm.GetComponent<SpriteRenderer> (); RightUpperArmAnim = RightUpperArm.GetComponent<Animator> (); }