/** * \brief Adds a callback function to the HP component, so that * the camera shakes when the player's HP reaches zero. * \param void * \return void */ private void Start() { GetComponent <HP>().AddDeathCallback(() => { float angle = Random.Range(-180, 179); float magnitude = Random.Range(minShake, maxShake); cam.Rotate(TrigPhysics.GetVelocity(angle, magnitude)); }); }
/** * \brief Fires bullets. * \param void * \return void */ void Fire() { if (Time.timeScale != 0.0f) { GameObject bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.transform.rotation = transform.rotation; bullet.GetComponentInParent <SphereTraveller>().Rotation = st.Rotation; Inertia inertia = bullet.GetComponentInParent <Inertia>(); // get standard velocity float stdSpeed = bullet.GetComponentInParent <SphereTraveller>().speed; float stdAngle = turretTransform.localRotation.eulerAngles.y; inertia.StdVelocity = TrigPhysics.GetVelocity(stdAngle + Random.Range(-spread, spread), stdSpeed); // get inherited velocity inertia.InheritedVelocity = st.LastDirection; // get angle inertia.Angle = stdAngle; } }