Beispiel #1
0
    public void SpawnPowerup(Vector3 direction, int powerupIdx, string powerupId)
    {
        // Spawn a powerup s.t. it's contained in the sun but "touches" it from within:
        //              ______
        //          ___/      \___
        //        _/              \_
        //       /                  \
        //      |                    |
        //     / __                   \
        // /__ |/  \                  |
        // \   |\__/                  |
        //     \                      /
        //      |                    |
        //       \_                _/
        //         \___        ___/
        //             \______/
        //
        GameObject powerupObj = Instantiate(
            powerupPrefabs[powerupIdx],
            Vector3.zero,
            Tools.Geometry.UpRotation(-direction));

        powerups[powerupId] = powerupObj.GetComponentInChildren <Powerup>();

        // We need the powerup to be offset some positive value in the direction, so gravity takes effect
        float offset = Mathf.Max(0.1f, sun.Radius() - powerups[powerupId].Radius());

        powerupObj.transform.position = direction.normalized * offset;

        // Init field values
        powerups[powerupId].direction   = direction;
        powerups[powerupId].powerupCtrl = this;
        powerups[powerupId].powerupId   = powerupId;
        powerups[powerupId].powerupIdx  = powerupIdx;
    }
    // Update is called once per frame
    void Update()
    {
        // Set position to surface of sun, with up rotation toward player and forward direction towards player forward
        Vector3 playerDirection = transform.position.normalized;

        sunMarker.position = Vector3.Lerp(sunMarker.position, (0.5f + sun.Radius()) * playerDirection, 0.1f);
        sunMarker.rotation = Quaternion.LookRotation(transform.forward, playerDirection);
    }