예제 #1
0
    private void OnEnable()
    {
        referenceGO       = GameObject.Find("GameManager");
        gameManagerScript = referenceGO.GetComponent <GameManager>();



        soundGO     = GameObject.Find("SoundManager");
        soundScript = soundGO.GetComponent <SplatSound>();

        assetsList = GameObject.Find("AssetsHolder");
        ingChoice  = UnityEngine.Random.Range(0, 13);

        cameraHolderGO = GameObject.Find("CameraHolder");
        cameraScript   = cameraHolderGO.GetComponent <MoveCameraUpwards>();

        scoreHolderGO = GameObject.Find("GameplayScreen").transform.GetChild(0).gameObject;
        scoreScript   = scoreHolderGO.GetComponent <ScoreText>();

        if (LastCube == null)
        {
            LastCube = GameObject.Find("Start").GetComponent <MovingCube>();
        }
        else
        {
            CurrentCube = this;
            GetComponent <Renderer>().material = assetsList.transform.GetChild(ingChoice).gameObject.GetComponent <Renderer>().material;
            GetComponent <MeshFilter>().mesh   = assetsList.transform.GetChild(ingChoice).gameObject.GetComponent <MeshFilter>().mesh;

            moveSpeed = gameManagerScript.cubeSpeed;

            if (baseVertices == null)
            {
                baseVertices = GetComponent <MeshFilter>().mesh.vertices;
            }

            var vertices = new Vector3[baseVertices.Length];

            for (var i = 0; i < vertices.Length; i++)
            {
                var vertex = baseVertices[i];
                vertex.x = vertex.x * 1;
                vertex.y = vertex.y * 10;
                vertex.z = vertex.z * 1;

                vertices[i] = vertex;
            }

            GetComponent <MeshFilter>().mesh.vertices = vertices;

            if (recalculateNormals)
            {
                GetComponent <MeshFilter>().mesh.RecalculateNormals();
                GetComponent <MeshFilter>().mesh.RecalculateBounds();
            }
        }
        //Changes Scale of Spawned Cube?
        //transform.localScale = new Vector3(LastCube.transform.localScale.x, transform.localScale.y, LastCube.transform.localScale.z);
        //transform.localScale = new Vector3(x: 1f, y: 0.1f, z: 1f);
        transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z);

        StartCoroutine(DespawnTimer());
    }
예제 #2
0
        // Move the shot.
        private void moveTimer_Tick(object sender, EventArgs e)
        {
            // Update the velocity components.
            ShotVy += AccY;

            // Calculte the shot's new position.
            ShotPosition.X += ShotVx;
            ShotPosition.Y += ShotVy;

            // See if we hit the target.
            RectangleF shotRect = MakeRect(ShotPosition, ShotR);

            if (shotRect.IntersectsWith(TargetRect))
            {
                // We hit it. Stop.
                moveTimer.Enabled = false;

                // Play the explosion sound.
                BoomSound.controls.play();

                // Save the hit spot.
                RectangleF hitRect = new RectangleF(
                    HouseRect.X, HouseRect.Bottom - FireHeight,
                    FireWidth, FireHeight);
                Hits.Add(hitRect);

                // Move the house.
                PositionHouse();

                // Reset the shot.
                ShotPosition = CrossCenter;
            }
            else if ((ShotPosition.X < 0) ||
                     (ShotPosition.X > scenePictureBox.ClientSize.Width) ||
                     (ShotPosition.Y > GroundRect.Top))
            {
                // The shot has left the scene. Stop.
                moveTimer.Enabled = false;

                // Save this position as a miss.
                if ((ShotPosition.X > 0) &&
                    (ShotPosition.X < scenePictureBox.ClientSize.Width))
                {
                    // Adjust the shot so it sits on the ground.
                    float dy = ShotPosition.Y - GroundRect.Top;
                    float dx = ShotVx * dy / ShotVy;
                    ShotPosition.X -= dx;
                    ShotPosition.Y -= dy;

                    // Play the splat sound.
                    SplatSound.Play();

                    // Save the location where the shot hit the ground.
                    Misses.Add(MakeRect(ShotPosition, ShotR));
                }

                // Reset the shot.
                ShotPosition = CrossCenter;
            }

            // Redraw.
            scenePictureBox.Refresh();
        }