public void Create(BulletPowerup powerup, Vector3 position, Vector3 direction, bool expireWhenNotVisible, bool infecter = false) { // Check whether there are any bullets left. if (available != Capacity) { // Get the bullet. GameObject bullet = bullets[available]; // Set the available bullet to the bullet linked to this one. available = links[available]; // Activate the bullet. bullet.SetActive(true); // Get the bullet script. scrBullet bulletScript = bullet.GetComponent <scrBullet>(); bulletScript.Init(powerup, position, direction, expireWhenNotVisible, infecter); } }
public void Init(BulletPowerup powerup, Vector3 position, Vector2 direction, bool expireWhenNotVisible, bool infecter) { life = 0; Expired = false; ExpireWhenNotVisible = expireWhenNotVisible; Infecter = infecter; transform.position = position; Direction = direction; transform.forward = direction; Speed = powerup.Speed; Damage = powerup.Size; Wiggle = powerup.Wiggle; Erratic = powerup.Erratic; Penetrative = powerup.Penetrative; if (Penetrative) { transform.localScale = powerup.Size * new Vector3(1.5f, 0.3f, 0.3f); } else { transform.localScale = powerup.Size * Vector3.one; } transform.Find("Core").renderer.material.color = powerup.Colour; transform.Find("Glow").renderer.material.SetColor("_TintColor", new Color(powerup.Colour.r * 0.5f, powerup.Colour.g * 0.5f, powerup.Colour.b * 0.5f, 0.0625f)); if (!powerup.Homing) { StandardStart(); updateBehaviour = StandardUpdate; fixedUpdateBehaviour = StandardFixedUpdate; } else { HomingStart(); updateBehaviour = HomingUpdate; fixedUpdateBehaviour = HomingFixedUpdate; } }
void ProcessInput() { simulatedCursorOffset += new Vector2(Input.GetAxis("Mouse X") / Screen.width, Input.GetAxis("Mouse Y") / Screen.height) * 1000 * SimulatedCursorSensitivity; if (simulatedCursorOffset.magnitude > simulatedCursorRadius) { simulatedCursorOffset = simulatedCursorOffset.normalized * simulatedCursorRadius; } SimulatedCursorPosition = (Vector2)transform.position + simulatedCursorOffset; // Move the camera half way between the player and simulated cursor. Vector2 half = Vector2.Lerp(transform.position, SimulatedCursorPosition, 0.5f); Camera.main.transform.position = new Vector3(half.x, half.y, Camera.main.transform.position.z); // Get the aim direction. Vector2 aim = SimulatedCursorPosition - (Vector2)transform.position; if (aim != Vector2.zero) { aim.Normalize(); } AimDirection = aim; // Face the simulated mouse position. float roll = Mathf.Atan2(aim.y, aim.x); transform.eulerAngles = new Vector3(0, 0, Mathf.Rad2Deg * roll); // Get the movement direction. Vector2 move = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); if (move != Vector2.zero) { move.Normalize(); } MoveDirection = move; // Check for shooting. if (Input.GetButton("Fire")) { if (fireTimer >= 1) { if (Powerups.Count != 0) { if (fireMode == 0) { bulletPool.Create(Powerups.Peek(), transform.TransformPoint(gunOffsets[0]), transform.right, true); } else { BulletPowerup p = Powerups.Peek(); p.Wiggle = -p.Wiggle; bulletPool.Create(p, transform.TransformPoint(gunOffsets[1]), transform.right, true); } --powerupShotsLeft; if (powerupShotsLeft == 0) { powerupShotsLeft = powerupShotsMax; Powerups.Dequeue(); scrGUI.Instance.DequeuePowerup(); } // ...I don't like iiiit...I want to recooode alll of thiiiiiss...its getting on my neeerves...but there's no tiiime!! if (Powerups.Count != 0) { scrGUI.Instance.transform.Find("PowerupQueue").GetComponent <Text>().text = "Powerup Queue - [ " + powerupShotsLeft + " Shots Left ]"; } else { scrGUI.Instance.transform.Find("PowerupQueue").GetComponent <Text>().text = "Powerup Queue - [ NO POWERUPS ]"; } } else { if (fireMode == 0) { bulletPool.Create(new BulletPowerup(scrNodeMaster.ColCoreUninfected, 120, 1, 0, 0, 0, false, false), transform.TransformPoint(gunOffsets[0]), transform.right, true); } else { bulletPool.Create(new BulletPowerup(scrNodeMaster.ColCoreUninfected, 120, 1, 0, 0, 0, false, false), transform.TransformPoint(gunOffsets[1]), transform.right, true); } } audio.PlayOneShot(FireSound); fireMode = (fireMode == 0 ? 1 : 0); fireTimer = 0; } } // Check for bomb. if (bombTimer < bombDelay) { bombTimer += Time.deltaTime; } else { if (Input.GetButtonDown("Bomb")) { StartCoroutine(DeployBomb(transform.position)); } } }