Exemple #1
0
    public void OnAction(GameEventData gameEventData)
    {
        CameraController cameraController  = GameController.Instance.CameraControllerInstance;
        Vector3          cameraPosition    = cameraController.transform.position;
        float            frustumHalfHeight = Mathf.Abs(cameraPosition.z) * Mathf.Tan(cameraController.CameraComponent.fieldOfView * 0.5f * Mathf.Deg2Rad);
        float            cameraTopBound    = cameraPosition.y + frustumHalfHeight;

        cameraTopBound += 2.0f;             // idk arbitrary thing so the bomb's center isn't right on the screen edge but slightly outside

        for (int i = 0; i < gameEventData.Number; ++i)
        {
            float   x             = Random.Range(-gameEventData.Offset.x, gameEventData.Offset.x);
            float   y             = Random.Range(-gameEventData.Offset.y, gameEventData.Offset.y);
            Vector3 offset        = new Vector2(x, y).ToVec3();
            Vector3 spawnPosition = new Vector2(gameEventData.Position.x, cameraTopBound + gameEventData.Position.y).ToVec3();

            float   spread  = Random.Range(-gameEventData.Spread, gameEventData.Spread);
            float   radians = (gameEventData.Rotation + spread) * Mathf.Deg2Rad;
            float   cos     = Mathf.Cos(radians);
            float   sin     = Mathf.Sin(radians);
            Vector2 force   = new Vector3(cos, sin) * gameEventData.Speed.Get();

            MonoBehaviour bomb = Object.Instantiate(gameEventData.Object);
            bomb.transform.Reset();
            bomb.transform.position = spawnPosition + offset;
            BSGFakePhysics fakePhysics = bomb.GetComponent <BSGFakePhysics>();
            if (fakePhysics != null)
            {
                fakePhysics.AddForce(force);
            }
        }
    }
    private void Update()
    {
        if (BombPrefabs.Length > 0 && mBombsPerSecond > 0.0f)
        {
            mSpawnTimer += Time.deltaTime;
            float depth    = GameController.Instance.FurthestDepth;
            float interval = 1.0f / Mathf.Min(mBombsPerSecond + mRampPerDepth * depth, mMaxBombsPerSecond != 0.0f ? mMaxBombsPerSecond : float.MaxValue);
            if (mSpawnTimer >= interval)
            {
                mSpawnTimer -= interval;

                Vector2 force = new Vector2(Random.Range(0.0f, 0.0f), 0.0f);

                MonoBehaviour bomb = Instantiate(BombPrefabs.GetRandom());
                bomb.transform.Reset();
                bomb.transform.position = new Vector2(Random.Range(-8.0f, 8.0f), 10.0f);
                BSGFakePhysics fakePhysics = bomb.GetComponent <BSGFakePhysics>();
                if (fakePhysics != null)
                {
                    fakePhysics.AddForce(force);
                }
            }
        }
    }