// Use this for initialization
    void Start()
    {
        main = this;

        dangerMarkers = new List <HazardMarker>();
        personMarkers = new List <HazardMarker>();
        fallMarkers   = new List <HazardMarker>();
    }
 // Use this for initialization
 void Start()
 {
     cameraController       = FindObjectOfType <CameraController> ();
     playerController       = FindObjectOfType <PlayerController> ();
     scoreController        = FindObjectOfType <ScoreController> ();
     platformGenerator      = FindObjectOfType <PlatformGenerator> ();
     distanceController     = FindObjectOfType <DistanceController>();
     hazardController       = FindObjectOfType <HazardController>();
     gameOverCanvas.enabled = false;
     started = false;
 }
示例#3
0
文件: BrickBoss.cs 项目: smhx/Spawn
 void Awake()
 {
     PScolor  = standardPS.colorOverLifetime;
     tracker  = GameObject.FindWithTag("CollisionTracker").GetComponent <CollisionTracker> ();
     sr       = GetComponent <SpriteRenderer>();
     spawner  = GameObject.FindWithTag("BrickSpawner").GetComponent <BrickSpawner> ();
     gameInit = GameObject.FindWithTag("GameInitializer").GetComponent <GameInitializer> ();
     hb       = GetComponent <HazardBrick>();
     gm       = GameObject.FindWithTag("GameManager").GetComponent <GameSceneManager>();
     hc       = GameObject.FindWithTag("HazardController").GetComponent <HazardController>();
 }
    // Update
    public void Active()
    {
        if (Time.time - roundStartTime < suddenDeathTime) // Check if sudden death has started.
        {
            return;
        }
        if (Time.time - lastTime >= curPace) // Check if we should spawn a hazard
        {
            lastTime    = Time.time;
            shouldSpawn = true;
        }
        if (shouldSpawn) // If we should spawn a hazard
        {
            GameObject       newHaz    = Instantiate(hazardPrefab, Vector3.zero, Quaternion.identity);
            HazardController newHazard = newHaz.GetComponent <HazardController>();
            GameObject       newShad   = Instantiate(shadowPrefab, Vector3.zero, Quaternion.identity);

            hazardList.Add(newHazard);
            shadowList.Add(newShad);

            Vector2 spawnPoint = new Vector2(Random.Range(-10f, 10f), Random.Range(-5f, 5f));
            newHazard.Initialize(spawnPoint, travelTime);
            newShad.transform.position = spawnPoint;

            shouldSpawn = false;
        }
        for (int i = 0; i < hazardList.Count; i++)
        {
            if (hazardList[i] != null)
            {
                hazardList[i].DoUpdate();
            }
        }
        if (!isMaxSpeed)
        {
            curPace -= 0.001f;

            if (curPace <= finalPace)
            {
                curPace    = finalPace;
                isMaxSpeed = true;
            }
        }
    }
    /// <summary>
    /// Detects if a <c>Hazard</c> comes into contact with the player's sheild.
    /// If so, the player is bounced back.
    /// If the <c>Hazard</c> has a reaction to being hit (e.g. <c>Projectiles</c> being reflected),
    /// then that rection is triggered.
    /// </summary>
    /// <param name="collider">Information about the collision that ocurred.</param>
    /// <seealso cref="HazardController"/>
    private void OnTriggerEnter2D(Collider2D collider)
    {
        GameObject encounter = collider.gameObject;

        if (encounter.CompareTag("Hazard") || encounter.CompareTag("Projectile") || encounter.CompareTag("Enemy") || encounter.CompareTag("Explosion"))
        {
            if (timer == 0)
            {
                sFXPlayer.clip = Resources.Load <AudioClip>("Sounds/Bounce");
                sFXPlayer.Play();
                if (anim != null)
                {
                    anim.SetTrigger("Hit");
                }
                HazardController hazard = encounter.GetComponent <HazardController>();
                if (hazard == null)
                {
                    hazard = encounter.GetComponentInParent <HazardController>();
                }
                if (hazard == null)
                {
                    hazard = encounter.GetComponentInChildren <HazardController>();
                }
                Vector2 speed = new Vector2();
                float   hMass = 1;
                if (hazard != null)
                {
                    speed = hazard.GetMoveDirection();
                    if (encounter.CompareTag("Explosion"))
                    {
                        speed = encounter.transform.position - player.transform.position;
                        speed.Normalize();
                        speed *= encounter.GetComponent <ExplosionController>().speed;
                    }
                    hMass = hazard.mass;
                }
                Impact(speed, hMass);
                if (hazard != null)
                {
                    hazard.OnShieldCollision(gameObject);
                }

                timer = reflectionDelay;
                projectileCount++;
                if (projectileCount >= 5)
                {
                    if (pC.AddDash())
                    {
                        projectileCount = 0;
                    }
                }

                if (headColor.transform.childCount > 1)
                {
                    changeTailColor(false);
                }
                else
                {
                    headColor.transform.GetChild(0).gameObject.SetActive(false);
                }
            }
        }
    }