コード例 #1
0
 /// <summary>
 /// Manages collisions between projectile and other game objects
 /// </summary>
 /// <param name="other">Other.</param>
 void OnCollisionEnter2D(Collision2D other)
 {
     // Player loses and heart, projectile despawns, and player audio is triggered
     if (other.collider.CompareTag("Player"))
     {
         GameObject.FindGameObjectWithTag("playerdeath").GetComponent <AudioSource>().Play();
         Destroy(gameObject);
         other.gameObject.GetComponent <Player> ().Die();
     }
     else if (other.collider.CompareTag("shield"))
     {
         //Does nothing if it collides with shield
     }
     else if (other.collider.CompareTag("turret"))
     {
         //turret is destroyed, turret death audio is triggered, projectile despawns
         GameObject.FindGameObjectWithTag("enemydeath").GetComponent <AudioSource>().Play();
         EnemyCount.KilledEnemy();
         Destroy(gameObject);
         Destroy(other.collider.gameObject);
     }
     else
     {
         // if projectile hits any other object it is destroyed
         Destroy(gameObject);
     }
 }
コード例 #2
0
 public int EnCount = 0; //场景中的敌人数量
 private void Awake()
 {
     _Instance = this;
     for (int i = 0; i < enemy.Length; i++)
     {
         enemyList.Add(enemy[i]);
     }
     EnCount = enemyList.Count;
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        EnemyCount fixTracker = fixCount.GetComponent <EnemyCount>();

        if (fixTracker.fixCount == fixTracker.fixRequired)
        {
            audioSource.Stop();
        }
    }
コード例 #4
0
    public void Fix()
    {
        broken = false;
        rigidbody2D.simulated = false;

        animator.SetTrigger("Fixed");
        EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>();

        count.fixCount += 1;

        smokeEffect.Stop();
    }
コード例 #5
0
ファイル: Quest.cs プロジェクト: ShaDream/VoidTime
 public Quest(string name,
              int reward,
              EnemyCount count,
              EnemyDifficult difficult,
              Func <Ship> beginQuest)
 {
     Name       = name;
     Reward     = reward;
     Count      = count;
     Difficult  = difficult;
     Status     = QuestStatus.NotStarted;
     BeginQuest = beginQuest;
 }
コード例 #6
0
    public void DisplayDialog()
    {
        EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>();

        if (count.fixCount == count.fixRequired)
        {
            timerDisplay = displayTime;
            winDialog.SetActive(true);
            canWait = true;
        }
        else
        {
            timerDisplay = displayTime;
            dialogBox.SetActive(true);
        }
    }
コード例 #7
0
    void OnCountChanged()
    {
        unitInfo.UnitCount.text = EnemyCount.ToString();
        int totalCost = 0;

        for (int i = 0; i < EnemyCount; i++)
        {
            totalCost += selectedUnit.Cost;
        }
        if (GameController.instance.Money > totalCost + CalculateTotalCost())
        {
            unitInfo.UnitTotalCost.color = new Color32(0, 236, 21, 255);
        }
        else
        {
            unitInfo.UnitTotalCost.color = new Color32(203, 7, 36, 255);
        }
        unitInfo.UnitTotalCost.text = totalCost.ToString() + "$";
    }
コード例 #8
0
    public void PrepareWaves()
    {
        //gives the path
        string filePath = ProjectPaths.RESOURCES_MAP_SETTINGS + MapTypes.GetName(typeof(MapTypes), _mapType) + ".txt";

        Debug.Log(filePath);
        //reads the lines in the path
        string[] rows = File.ReadAllLines(filePath);

        //iterates through all the lines
        int breakPoint = 0;

        for (int i = 0; i < rows.Length; i++)
        {
            //saves the point where the symbol is
            if (rows[i].Contains("#"))
            {
                breakPoint = i + 1;
                break;
            }
        }

        //create empty array with required size
        string[] waves = new string[rows.Length - breakPoint];

        //copy this array to the other array
        Array.Copy(rows, breakPoint, waves, 0, rows.Length - breakPoint);


        //each wave in waves, turn into two ints
        //maybe use a string.somefunction() to separate the numbers?
        //add to List<Vector2Int>();
        foreach (string wave in waves)
        {
            string[] enemyCounts = wave.Split(' ');
            //Debug.Log(enemyCounts[0]);
            //Debug.Log(enemyCounts[1]);
            EnemyCount enemyCount = new EnemyCount(Convert.ToInt32(enemyCounts[0]), Convert.ToInt32(enemyCounts[1]));
            WaveList.Add(enemyCount);
        }
    }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>();

        if (count.fixCount == count.fixRequired && canPlay == true)
        {
            PlaySound(victory);
            canPlay = false;
        }
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        if (Input.GetKeyDown(KeyCode.X) || Input.GetButtonDown("Fire1"))
        {
            //RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.zero * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.down * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                Debug.Log("Raycast has hit the object " + hit.collider.gameObject);
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }

                else
                {
                    //ResourceCube();
                    ResourceCube cube = hit.collider.GetComponent <ResourceCube>();
                    cube.GetResources();
                    Destroy(hit.collider.gameObject);
                }
            }
        }

        //if(Input.GetKeyDown(KeyCode.C) && ammo > 0)
        //{
        //   Launch();

        //  PlaySound(throwSound);
        //}
        if (Input.GetButtonDown("Fire3") && ammo > 0)
        {
            Launch();

            PlaySound(throwSound);
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        if (currentHealth <= 0)
        {
            SceneManager.LoadScene(currentScene.name);
        }
    }