コード例 #1
0
    //Simple target will be a score giving target on hit. and a time sucking target on miss.

    public override void onClick(GameController game)
    {
        foreach (BaseTarget target in game.getTargets())
        {
            if (target.getTargetLayerOrder() > getTargetLayerOrder())
            {
                Collider2D targetCollider = target.gameObject.GetComponent <Collider2D>();
                if (Physics2D.IsTouching(targetCollider, gameObject.GetComponent <Collider2D>()))
                {
                    Debug.Log("Invalid!");
                    game.timeBonus(-1f);
                    return;
                }
            }
        }

        //What to do if it's a valid click.
        Debug.Log("Valid!");
        game.getCurrentPlayer().addScore(1);
        game.RemoveTarget(this);
    }
コード例 #2
0
 private void Expl()
 {
     if (isEnabled)
     {
         GameObject vfx = Instantiate(particleVfx);
         vfx.transform.position = transform.position;
         foreach (FencingMates_Player player in FindObjectsOfType <FencingMates_Player>())
         {
             if (Physics2D.IsTouching(player.GetComponent <BoxCollider2D>(), GetComponent <CircleCollider2D>()))
             {
                 player.StartCoroutine(player.DecreaseHp(damage));
             }
         }
         if (expl != null)
         {
             AudioSource.PlayClipAtPoint(expl, Camera.main.transform.position, 1f);
         }
         Destroy(vfx, 3f);
         Destroy(gameObject);
     }
 }
コード例 #3
0
    public bool IsGrounded(GameObject subLayer)
    {
        Collider2D playerCol = player.GetComponent <Collider2D>();
        Collider2D enemyCol  = enemy.GetComponent <Collider2D>();

        foreach (Transform t in subLayer.transform)
        {
            if (t.GetComponent <EdgeCollider2D>())
            {
                if (Physics2D.IsTouching(t.GetComponent <EdgeCollider2D>(), playerCol))
                {
                    return(true);
                }
                if (Physics2D.IsTouching(t.GetComponent <EdgeCollider2D>(), enemyCol))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
コード例 #4
0
    void Update()
    {
        if (Physics2D.IsTouching(col, playerCol))
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (!GameManager.instance.techOpen)
                {
                    GameManager.instance.techOpen = true;
                    techCanvas.enabled            = true;

                    playerCol.gameObject.GetComponent <PlayerMovement>().enabled = false;
                }
                else
                {
                    GameManager.instance.techOpen = false;
                    techCanvas.enabled            = false;
                    playerCol.gameObject.GetComponent <PlayerMovement>().enabled = true;
                }
            }
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        if (gameObject.tag == "Robot Wall")
        {
            if (controller.characterselect == 3 && controller.ability == true)
            {
                animator.SetBool("start", true);
            }
            if (Physics2D.IsTouching(obstacleCollider, playerCollider))
            {
                controller.death = true;
            }
        }

        if (gameObject.tag == "Robot Floor")
        {
            if (controller.characterselect == 3 && controller.ability == true)
            {
                animator.SetBool("start", true);
            }
        }
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (cameraMove != null && cameraMove.isPlayerDead == true)
        {
            gameEnded = true;
        }
        else
        {
            gameEnded = false;
        }

        if (Input.GetKeyDown(KeyCode.Space) && SceneManager.GetActiveScene().buildIndex == 0)
        {
            if (!source.isPlaying)
            {
                source.Play();
            }
            PlayGame();
        }
        if (gameEnded && Physics2D.IsTouching(player, box))
        {
            gameIsDone.SetActive(true);
        }

        if (Input.GetKeyDown(KeyCode.Space) && gameIsDone.activeSelf == true && SceneManager.GetActiveScene().buildIndex == 3)
        {
            BackToMenu();
        }

        if (Input.GetKeyDown(KeyCode.Escape) && SceneManager.GetActiveScene().buildIndex != 0)
        {
            BackToMenu();
        }

        if (Input.GetKeyDown(KeyCode.Escape) && SceneManager.GetActiveScene().buildIndex == 0)
        {
            QuitGame();
        }
    }
コード例 #7
0
    // Update is called once per frame
    void Update()
    {
        handPos = Mathf.Clamp(handPos, 2.25f, 4f);
        hand.transform.localPosition = new Vector3(1.0f, handPos, 1.0f);
        if (mini.finish)
        {
            sparkle.enabled = true;
        }
        if (mini.timerGet <= 0)
        {
            Reset();
        }

        if (Physics2D.IsTouching(dogBox, handBox) && !hasCollided)
        {
            sound.Play();
            Debug.Log("barlk bark");
            numPets++;
            hasCollided = true;
        }
        if (!Physics2D.IsTouching(dogBox, handBox))
        {
            hasCollided = false;
        }
        if (numPets >= 5)
        {
            mini.finish = true;
        }
        if (Input.GetButton(mini.button))
        {
            handPos -= 5f * Time.deltaTime;
            //numPets++;
        }
        else
        {
            handPos += 4f * Time.deltaTime;
        }
    }
コード例 #8
0
 void Update()
 {
     // 1. Move this object toward target point;
     // 2. If this object reached target point:
     // 2.1 target point changes to next point in wayPoint array.
     if (Physics2D.IsTouching(collider, colliderother))
     {
         Debug.Log("Stop");
         return;
     }
     times = (wayPoints [targetPointIndex].position - transform.position).magnitude;
     Debug.Log("The distace:" + times);
     transform.position = Vector3.Lerp(transform.position, wayPoints[targetPointIndex].position, speed * Time.deltaTime);
     if (transform.position == wayPoints [targetPointIndex].position)
     {
         targetPointIndex++;
         targetPointIndex = targetPointIndex >= wayPoints.Length ? 0 : targetPointIndex;
     }
     //wayPoints.Length;
     //transform.position;
     //wayPoints [targetPointIndex].position;
     //Vector3.Lerp ();
 }
コード例 #9
0
 private void SelectUnit()
 {
     foreach (GameObject unit in gameController.GetComponent <GameController>().playerUnitList)
     {
         try
         {
             CharacterStats unitStats = unit.GetComponent <CharacterStats>();
             if (unitStats.hasMoved == 0 && Physics2D.IsTouching(col, unit.GetComponent <BoxCollider2D>()))
             {
                 currentlySelectedUnit = unit;
                 selectedUnitLastPos   = new Vector3(currentlySelectedUnit.transform.position.x,
                                                     currentlySelectedUnit.transform.position.y,
                                                     currentlySelectedUnit.transform.position.z);
                 ActivateValidSpaceMap();
                 return;
             }
         }
         catch (Exception e)
         {
             continue;
         }
     }
 }
コード例 #10
0
ファイル: dummy.cs プロジェクト: EdMarrs/ChaoticCatacombs
    void Update()
    {
        if (Physics2D.IsTouching(whipRef, GetComponent <Collider2D>()))
        {
            hp -= 1;
        }

        if (hp == 0)
        {
            Destroy(gameObject);

            if (itemChanceRoll >= 100 - chanceToSpawnAnItem)
            {
                GetComponent <Renderer>().enabled = true;
                GameObject itemToSpawn = items[Random.Range(0, items.Length - 1)];
                Instantiate(itemToSpawn, new Vector3(transform.position.x, transform.position.y + 1.1f), Quaternion.identity);
            }
            else
            {
                GetComponent <Renderer>().enabled = false;
            }
        }
    }
コード例 #11
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!Physics2D.IsTouching(checkCollider, collision))
        {
            return;
        }
        if (collision.isTrigger)
        {
            return;
        }
        DestroyOnFire destroyOnFire = collision.gameObject.GetComponent <DestroyOnFire>();

        if (destroyOnFire)
        {
            destroyOnFire.Destroy();
        }
        DamageOnFire damageOnFire = collision.gameObject.GetComponent <DamageOnFire>();

        if (damageOnFire)
        {
            damageOnFire.isOnFire = true;
        }
    }
コード例 #12
0
    void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            bool differentLadderFound = false;
            foreach (Ladder ladder in FindObjectsOfType <Ladder>())
            {
                if (Physics2D.IsTouching(_player.GetComponent <Collider2D>(), ladder.GetComponent <Collider2D>()) && ladder != gameObject.GetComponent <Ladder>())
                {
                    differentLadderFound = true;
                }
            }
            if (!differentLadderFound)
            {
                _player.GetComponent <Rigidbody2D>().isKinematic = false;
                _player.onLadder = false;

                // ClimbAnimation.SetTrigger("Jump");
                ClimbAnimation.ResetTrigger("Climbing");
                ClimbAnimation.SetTrigger("Land");
                ClimbAnimation.speed = 1f;
            }
        }
    }
コード例 #13
0
    void FixedUpdate()
    {
        if (player != null && killPlane != null && nextLevel != null)
        {
            /*if (Physics2D.IsTouching(player, killPlane))
             * {
             *  CharacterContollerScript controllerScript = player.gameObject.GetComponent<CharacterContollerScript>();
             *  controllerScript.lives = 0;
             * }*/
            if (Physics2D.IsTouching(player, nextLevel))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
            }
        }

        if (box != null)
        {
            if (Physics2D.IsTouching(player, box))
            {
                CameraMovementScript cameraM = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraMovementScript>();
                cameraM.isPlayerDead = true;
            }
        }
    }
コード例 #14
0
ファイル: Botol.cs プロジェクト: EChristian48/Corona-Game-PTS
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch   touch    = Input.GetTouch(0);
            Vector2 touchPos = mainCam.ScreenToWorldPoint(touch.position);

            if (touch.phase == TouchPhase.Began)
            {
                RaycastHit2D hit2D = Physics2D.Raycast(touchPos, Vector2.zero);

                if (hit2D.collider == col)
                {
                    transform.position = touchPos;
                    isHeld             = true;
                }
            }

            if (touch.phase == TouchPhase.Moved && isHeld)
            {
                transform.position = touchPos;
            }

            if (touch.phase == TouchPhase.Ended)
            {
                isHeld = false;

                if (Physics2D.IsTouching(col, tahiLalatsCol))
                {
                    Level2Event.current.BotolLepas();
                }

                transform.position = defaultPos;
            }
        }
    }
コード例 #15
0
 // Update is called once per frame
 void Update()
 {
     if (mini.timerGet <= 0)
     {
         Debug.Log("Resetting: Dino");
         Reset();
     }
     if (color)
     {
         if (dinoSpr.sprite != dinoColor)
         {
             sound.Play();
         }
         mini.finish    = true;
         dinoSpr.sprite = dinoColor;
     }
     else
     {
         dinoSpr.sprite = dinoBlank;
     }
     cursorPos += cursorSpeed * Time.deltaTime;
     cursor.transform.localPosition = new Vector3(cursorPos, 0.0f, 1.0f);
     if ((cursorPos >= cursorBound && cursorSpeed > 0f) || (cursorPos <= (cursorBound * -1) && cursorSpeed < 0f))
     {
         cursorSpeed *= -1;
     }
     if (Input.GetButtonDown(mini.button))
     {
         Debug.Log("Color them dinosaurs boyyyyy");
         cursorSpeed = 0;
         if (Physics2D.IsTouching(dinoBox, cursorBox))
         {
             color = true;
         }
     }
 }
コード例 #16
0
 void CheckPlayer()
 {
     isPlayer = Physics2D.IsTouching(bean, player);
 }
コード例 #17
0
        protected override bool TrackTarget()
        {
            if (Target == null)
            {
                return(false);
            }

            if (Target.IsDied || !Target.GameObj.activeSelf)
            {
                RaiseTargetDiedEvent();
                Target = null;

                return(false);
            }

            switch (CurrentAttackState)
            {
            case AttackState.NonAttacking:                     // started attacking
                if (Physics2D.IsTouching(_collider, Target.Collider))
                {
                    return(true);
                }
                else
                {
                    if (moveToTarget)
                    {
                        moveByTransform.AssignTransform(Target.GameObj.transform);
                        followingOrder = moveByTransform;
                    }
                    RaiseTargetOutOfRangeEvent();
                    return(false);
                }

            case AttackState.TargetInRange:
                if (!Physics2D.IsTouching(_collider, Target.Collider))
                {
                    if (moveToTarget)
                    {
                        moveByTransform.AssignTransform(Target.GameObj.transform);
                        followingOrder = moveByTransform;
                    }

                    RaiseTargetOutOfRangeEvent();
                    return(false);
                }
                else
                {
                    return(true);
                }

            case AttackState.TargetOutOfRange:
                if (Physics2D.IsTouching(_collider, Target.Collider))
                {
                    RaiseTargetInRangeEvent();
                    followingOrder = null;
                    return(true);
                }
                break;
            }
            return(false);
        }
コード例 #18
0
    // Update is called once per frame
    void Update()
    {
        if (weaponUpgradeCanvas.active)
        {
            hoverCanvas.active = false;

            if (currentlySelectedUnit == null)
            {
                foreach (Button button in weaponUpgradeButtonList)
                {
                    var image = button.GetComponent <Image>();
                    image.color = Color.red;
                }
                return;
            }

            CharacterStats currStats = currentlySelectedUnit.GetComponent <CharacterStats>();

            ColorWeaponUpgradeButtons();

            if (weaponBListIndex == -1)
            {
                weaponBListIndex = 0;
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                switch (weaponBListIndex)
                {
                case 0:
                    currStats.weaponMt += 1;
                    break;

                case 1:
                    currStats.hit += 5;
                    break;

                case 2:
                    currStats.crit += 5;
                    break;

                default:
                    break;
                }
                weaponBListIndex           = -1;
                weaponUpgradeCanvas.active = false;
                currentlySelectedUnit      = null;
                ColorWeaponUpgradeButtons();
                timeSinceLastButtonChange = 0.2f;
                return;
            }

            if (timeSinceLastButtonChange >= 0.2f)
            {
                bool moveHor = Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f;
                if (moveHor)
                {
                    if (Input.GetAxisRaw("Horizontal") == 1f)
                    {
                        if (weaponBListIndex < weaponUpgradeButtonList.Count - 1)
                        {
                            weaponBListIndex += 1;
                        }
                    }
                    else if (Input.GetAxisRaw("Horizontal") == -1f)
                    {
                        if (weaponBListIndex >= 1)
                        {
                            weaponBListIndex -= 1;
                        }
                    }
                    timeSinceLastButtonChange = 0.0f;
                }
                return;
            }

            timeSinceLastButtonChange += Time.deltaTime;
            return;
        }


        if (levelUpCanvas.active)
        {
            hoverCanvas.active  = false;
            transform.position  = currentlySelectedUnit.transform.position;
            moveTarget.position = currentlySelectedUnit.transform.position;

            if (Input.GetKeyDown(KeyCode.Space))
            {
                CharacterStats currStats = currentlySelectedUnit.GetComponent <CharacterStats>();

                levelUpInfoList[0].GetComponent <Text>().text = "" + currStats.characterName;
                levelUpInfoList[9].GetComponent <Text>().text = "" + currStats.level;

                levelUpInfoList[1].GetComponent <Text>().text = "+" + currStats.statGains[0];
                levelUpInfoList[2].GetComponent <Text>().text = "+" + currStats.statGains[1];
                levelUpInfoList[3].GetComponent <Text>().text = "+" + currStats.statGains[2];
                levelUpInfoList[4].GetComponent <Text>().text = "+" + currStats.statGains[3];
                levelUpInfoList[5].GetComponent <Text>().text = "+" + currStats.statGains[4];
                levelUpInfoList[6].GetComponent <Text>().text = "+" + currStats.statGains[5];
                levelUpInfoList[7].GetComponent <Text>().text = "+" + currStats.statGains[6];
                levelUpInfoList[8].GetComponent <Text>().text = "+" + currStats.statGains[7];

                levelUpInfoCanvas.active = true;
                levelUpCanvas.active     = false;
            }
            return;
        }
        if (levelUpInfoCanvas.active)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                CharacterStats currStats = currentlySelectedUnit.GetComponent <CharacterStats>();
                if (!didShowGrowths)
                {
                    levelUpInfoList[1].GetComponent <Text>().text = "" + currStats.maxHp;
                    levelUpInfoList[2].GetComponent <Text>().text = "" + currStats.Str;
                    levelUpInfoList[3].GetComponent <Text>().text = "" + currStats.Mag;
                    levelUpInfoList[4].GetComponent <Text>().text = "" + currStats.Skl;
                    levelUpInfoList[5].GetComponent <Text>().text = "" + currStats.Spd;
                    levelUpInfoList[6].GetComponent <Text>().text = "" + currStats.Luck;
                    levelUpInfoList[7].GetComponent <Text>().text = "" + currStats.Def;
                    levelUpInfoList[8].GetComponent <Text>().text = "" + currStats.Res;

                    didShowGrowths = true;
                    return;
                }
                else
                {
                    didShowGrowths           = false;
                    levelUpInfoCanvas.active = false;
                    if (currStats.level % 3 == 0)
                    {
                        weaponUpgradeCanvas.active = true;
                        weaponUpgradeOldStatsList[0].GetComponent <Text>().text = "" + currStats.weaponMt;
                        weaponUpgradeOldStatsList[1].GetComponent <Text>().text = "" + currStats.hit;
                        weaponUpgradeOldStatsList[2].GetComponent <Text>().text = "" + currStats.crit;

                        return;
                    }

                    currentlySelectedUnit = null;
                }
            }
            return;
        }

        if (enemyTurnCanvas.active)
        {
            hoverCanvas.active = false;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                enemyTurnCanvas.active = false;
                transform.position     = gameController.GetComponent <GameController>().enemyUnitList[0].transform.position;
                moveTarget.position    = transform.position;
            }
            return;
        }

        if (defeatCanvas.active)
        {
            hoverCanvas.active = false;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                ResetCurrScene();
                return;
            }
            return;
        }

        if (victoryCanvas.active)
        {
            hoverCanvas.active = false;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                // TODO: Implement transition to next scene after victory
                // Scene scene = SceneManager.GetActiveScene();
                moveTarget.position = transform.position;
                nextScene          += 1;
                if (nextScene >= 0 && nextScene < laterSceneNames.Count)
                {
                    SceneManager.LoadScene(laterSceneNames[nextScene]);
                }
                return;
            }

            return;
        }

        var gameControllerScript = gameController.GetComponent <GameController>();

        if (!gameControllerScript.isPlayerTurn)
        {
            hoverCanvas.active = false;
            return;
        }

        // Move the cursor towards the move target
        transform.position = Vector3.MoveTowards(transform.position, moveTarget.position, moveSpeed * Time.deltaTime);


        if (playerTurnCanvas.active)
        {
            hoverCanvas.active = false;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                playerTurnCanvas.active = false;
                transform.position      = gameController.GetComponent <GameController>().playerUnitList[0].transform.position;
                moveTarget.position     = transform.position;
            }
            return;
        }

        // Populate the unit info box with information on the current unit the player is hovering over, if one exists.
        PopulateHoverStats();


        // Handle the possible controls of the player: menus, moving the cursor, selecting units, attacking, etc.
        if (buttonCanvas.active || forecastCanvas.active)
        {
            if (selectedButtonIndex == -1)
            {
                selectedButtonIndex = 0;
            }
            int currIndex = 0;
            foreach (Button button in buttonList)
            {
                var image = button.GetComponent <Image>();
                if (currIndex != selectedButtonIndex)
                {
                    image.color = Color.black;
                }
                else
                {
                    image.color = Color.blue;
                }
                currIndex += 1;
            }

            if (isChoosingAttackTarget && forecastCanvas.active)
            {
                hoverCanvas.active = false;

                if (Input.GetKeyDown(KeyCode.C))
                {
                    isChoosingAttackTarget = false;
                    ResetCombatNums();
                    buttonCanvas.active   = true;
                    forecastCanvas.active = false;

                    transform.position  = currentlySelectedUnit.transform.position;
                    moveTarget.position = transform.position;
                }
                else if (Input.GetKeyDown(KeyCode.Space))
                {
                    Attack();
                    if (currentlySelectedUnit.GetComponent <CharacterStats>().currentHp > 0)
                    {
                        if (attackableTargets[attackTargetIndex].GetComponent <CharacterStats>().currentHp <= 0)
                        {
                            currentlySelectedUnit.GetComponent <CharacterStats>().exp += 100;
                            levelUpCanvas.active = true;

                            gameControllerScript.fallenEnemyUnitList.Add(attackableTargets[attackTargetIndex]);
                            gameControllerScript.enemyUnitList.Remove(attackableTargets[attackTargetIndex]);

                            ResetCombatNums();
                            isChoosingAttackTarget = false;
                            buttonCanvas.active    = false;
                            forecastCanvas.active  = false;
                            currentlySelectedUnit.GetComponent <CharacterStats>().hasMoved = 1;
                            return;
                        }
                        else
                        {
                            int currUnitLevel  = currentlySelectedUnit.GetComponent <CharacterStats>().level;
                            int enemyUnitLevel = attackableTargets[attackTargetIndex].GetComponent <CharacterStats>().level;

                            if (currUnitLevel <= enemyUnitLevel)
                            {
                                currentlySelectedUnit.GetComponent <CharacterStats>().exp += 30;
                            }
                            else if (currUnitLevel - enemyUnitLevel <= 2)
                            {
                                currentlySelectedUnit.GetComponent <CharacterStats>().exp += 15;
                            }
                            else
                            {
                                currentlySelectedUnit.GetComponent <CharacterStats>().exp += 5;
                            }
                            if (currentlySelectedUnit.GetComponent <CharacterStats>().exp >= 100)
                            {
                                levelUpCanvas.active = true;

                                ResetCombatNums();
                                isChoosingAttackTarget = false;
                                buttonCanvas.active    = false;
                                forecastCanvas.active  = false;
                                currentlySelectedUnit.GetComponent <CharacterStats>().hasMoved = 1;
                                return;
                            }
                        }
                    }

                    currentlySelectedUnit.GetComponent <CharacterStats>().hasMoved = 1;
                    currentlySelectedUnit = null;
                    ResetCombatNums();

                    isChoosingAttackTarget = false;
                    buttonCanvas.active    = false;
                    forecastCanvas.active  = false;
                }
                else if (Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f)
                {
                    if (Input.GetAxisRaw("Vertical") > 0)
                    {
                        if (attackTargetIndex > 0)
                        {
                            attackTargetIndex -= 1;
                            ForecastAttack();
                        }
                    }
                    else if (Input.GetAxisRaw("Vertical") < 0)
                    {
                        if (attackTargetIndex + 1 < attackableTargets.Count)
                        {
                            attackTargetIndex += 1;
                            ForecastAttack();
                        }
                    }
                }
                return;
            }
            if (!isChoosingAttackTarget)
            {
                bool moveVer = Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f;
                if (moveVer)
                {
                    if (Input.GetAxisRaw("Vertical") == 1f)
                    {
                        if (selectedButtonIndex >= 1)
                        {
                            selectedButtonIndex -= 1;
                        }
                    }
                    else if (Input.GetAxisRaw("Vertical") == -1f)
                    {
                        if (selectedButtonIndex < buttonList.Count - 1)
                        {
                            selectedButtonIndex += 1;
                        }
                    }
                }

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    switch (selectedButtonIndex)
                    {
                    case 0:
                        if (!CanAttack(currentlySelectedUnit.GetComponent <CharacterStats>().weaponRange))
                        {
                            selectedButtonIndex = 1;
                        }
                        else
                        {
                            buttonCanvas.active = false;
                            FindAttackableTargets(currentlySelectedUnit.GetComponent <CharacterStats>().weaponRange);
                            attackTargetIndex = 0;
                            ForecastAttack();
                            isChoosingAttackTarget = true;
                        }
                        break;

                    case 1:
                        currentlySelectedUnit.GetComponent <CharacterStats>().hasMoved = 1;
                        currentlySelectedUnit = null;
                        selectedButtonIndex   = -1;
                        buttonCanvas.active   = false;
                        break;

                    default:
                        break;
                    }
                }
                else if (Input.GetKeyDown(KeyCode.C))
                {
                    currentlySelectedUnit.transform.position = selectedUnitLastPos;
                    buttonCanvas.active = false;
                    selectedButtonIndex = -1;
                    ActivateValidSpaceMap();
                }
            }
            else
            {
            }
        }
        else
        {
            if (!isMovingUnit && Vector3.Distance(transform.position, moveTarget.position) <= 0.02f)
            {
                // Store whether the player is fully pressing the arrow keys to simplify later code
                bool moveHor = Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f;
                bool moveVer = Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f;


                // If the player is currently pressing any of the arrow keys fully, prepare to move the cursor based on what is pressed.
                if (moveHor || moveVer)
                {
                    Vector3 targetPosition = moveTarget.position;
                    if (moveHor && moveVer)
                    {
                        targetPosition = moveTarget.position + new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);
                    }
                    else
                    {
                        if (moveVer)
                        {
                            targetPosition = moveTarget.position + new Vector3(0, Input.GetAxisRaw("Vertical"), 0);
                        }
                        else
                        {
                            targetPosition = moveTarget.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0, 0);
                        }
                    }
                    if (!Physics2D.OverlapCircle(targetPosition, 0.1f, mapEdge) && currentlySelectedUnit == null)
                    {
                        moveTarget.position = targetPosition;
                    }

                    /*
                     * TODO: Implement pathing.
                     * 1) Track each position the cursor has gone to since selecting the unit (can add each target position
                     *      to a list of size s [where s is the move stat of the selected unit]). Keep an int to track the number of
                     *      spaces that have been used up.
                     * 2) When attempting to make a move, check it against map edge, then check the spaces int. If spaces int >= s,
                     *      check whether the distance target and currUnitPos (count x change and count y change) is <= s.
                     *          a) If distance <= s, erase ALL entries in the current list and form a new set of list entries by creating positions
                     *              by changing currUnitPos's x the needed number of times, then change the result's y the needed number of times.
                     *              WHEN DOING SO, RECALCULATE THE SPACES INT.
                     *          b) If distance > s, block the movement attempt.
                     * 3) After otherwise confirming the validity of a target position change, go through the path list and check if the
                     *      new target position is in the list. If so, set all entries after that index to null and adjust the spaces int accordingly.
                     * 4) If the move is valid per steps 2 and 3, check if the move would enter a forest tile. If so, check to ensure that
                     *      spaces int + 2 <= s.
                     *          a) If spaces int + 2 <= s, allow the move.
                     *          b) If spaces int + 2 > s, block the movement attempt.
                     * 5) When a cursor movement attempt is permitted, add it to the path list in the empty spot with the lowest index. If the
                     *      movement attempt would enter a forest, add it a second time.
                     * 4) When space is pressed after a unit is selected and the cursor is not on the same spot, have the unit move along the
                     *      entries in the path list one by one, until the target is reached.
                     */
                    else if (!Physics2D.OverlapCircle(targetPosition, 0.1f, mapEdge) && (!Physics2D.OverlapCircle(targetPosition, 0.1f, enemies)))
                    {
                        float distFromUnit = 0f;

                        distFromUnit += Mathf.Abs(targetPosition.x - selectedUnitLastPos.x);
                        distFromUnit += Mathf.Abs(targetPosition.y - selectedUnitLastPos.y);

                        if (distFromUnit <= currentlySelectedUnit.GetComponent <CharacterStats>().Mov)
                        {
                            moveTarget.position = targetPosition;
                        }
                    }
                }
                else if (Input.GetKeyDown(KeyCode.Space))
                {
                    if (currentlySelectedUnit == null)
                    {
                        this.SelectUnit();
                    }
                    else
                    {
                        foreach (GameObject unit in gameController.GetComponent <GameController>().playerUnitList)
                        {
                            if (unit == currentlySelectedUnit)
                            {
                                continue;
                            }
                            if (Physics2D.IsTouching(col, unit.GetComponent <BoxCollider2D>()))
                            {
                                return;
                            }
                        }
                        foreach (GameObject unit in gameController.GetComponent <GameController>().enemyUnitList)
                        {
                            if (unit == currentlySelectedUnit)
                            {
                                continue;
                            }
                            if (Physics2D.IsTouching(col, unit.GetComponent <BoxCollider2D>()))
                            {
                                return;
                            }
                        }
                        currentlySelectedUnit.transform.position = Vector3.MoveTowards(currentlySelectedUnit.transform.position, transform.position, moveSpeed * Time.deltaTime);
                        WipeValidSpaceMap();
                        isMovingUnit = true;
                    }
                }
                else if (Input.GetKeyDown(KeyCode.C))
                {
                    if (currentlySelectedUnit != null)
                    {
                        currentlySelectedUnit.transform.position = selectedUnitLastPos;
                        currentlySelectedUnit = null;
                        WipeValidSpaceMap();
                    }
                }
            }
            else if (isMovingUnit)
            {
                currentlySelectedUnit.transform.position = Vector3.MoveTowards(currentlySelectedUnit.transform.position, transform.position, moveSpeed * Time.deltaTime);
                if (Vector3.Distance(currentlySelectedUnit.transform.position, transform.position) <= 0.02f)
                {
                    isMovingUnit = false;
                    buttonCanvas.SetActive(true);
                }
            }
        }
    }
コード例 #19
0
 // Update is called once per frame
 void Update()
 {
     if (CurrentPart != null)
     {
         CurrentPart.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 8);
         Collider2D relativeCollider = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 2, 1);
         if (relativeCollider != null)
         {
             Transform relativeTransform = relativeCollider.transform;
             CurrentPart.transform.position    = relativeTransform.TransformPoint(Round(relativeTransform.InverseTransformPoint(CurrentPart.transform.position), 0.5f));
             CurrentPart.transform.eulerAngles = relativeTransform.eulerAngles + Round(CurrentPart.transform.eulerAngles - relativeTransform.eulerAngles, 90f);
         }
         if (Input.GetKeyDown(KeyCode.R))
         {
             CurrentPart.transform.Rotate(new Vector3(0, 0, 1), -90f);
         }
         if (Input.GetMouseButtonUp(0))
         {
             if ((transform.position - Input.mousePosition).magnitude < 300)
             {
                 Destroy(CurrentPart);
             }
             else
             {
                 BasePartBehaviour bph = CurrentPart.GetComponent <BasePartBehaviour> ();
                 foreach (BasePartBehaviour.connectionPoint v in bph.ConnectionPoints)
                 {
                     foreach (Collider2D c in Physics2D.OverlapPointAll(CurrentPart.transform.TransformPoint(v.LocalPosition)))
                     {
                         if (c.tag == "Part" && !Physics2D.IsTouching(c, bph.GetComponent <Collider2D>()))
                         {
                             CurrentPart.transform.SetParent(c.attachedRigidbody.transform);
                         }
                     }
                 }
                 if (CurrentPart.transform.parent == null)
                 {
                     GameObject newShip = Instantiate(BaseShip);
                     newShip.transform.position = CurrentPart.transform.position;
                     CurrentPart.transform.SetParent(newShip.transform);
                 }
                 CameraController cc = Camera.main.GetComponent <CameraController> ();
                 cc.Target = CurrentPart.transform.parent.gameObject;
                 cc.Offset = (cc.transform.position - CurrentPart.transform.parent.position);
                 foreach (Collider2D collider in CurrentPart.GetComponents <Collider2D> ())
                 {
                     collider.enabled = true;
                 }
                 CurrentPart = null;
             }
         }
     }
     else
     {
         if (Input.GetMouseButtonDown(0))
         {
             Collider2D co = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
             foreach (Collider2D c in Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition)))
             {
                 if (co == null)
                 {
                     co = c;
                 }
                 else
                 {
                     if ((c.transform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition)).magnitude < (co.transform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition)).magnitude)
                     {
                         co = c;
                     }
                 }
             }
             if (co != null)
             {
                 if (co.tag == "Part" && co.isActiveAndEnabled)
                 {
                     CurrentPart = co.gameObject;
                     Transform oldTransform = CurrentPart.transform.parent;
                     CurrentPart.transform.SetParent(null);
                     foreach (Collider2D collider in CurrentPart.GetComponents <Collider2D> ())
                     {
                         collider.enabled = false;
                     }
                     co.enabled = false;
                     if (oldTransform.childCount < 1)
                     {
                         Destroy(oldTransform.gameObject);
                     }
                 }
             }
             else
             {
                 foreach (Button b in PartPanelWindow.GetComponentsInChildren <Button>())
                 {
                     if ((Input.mousePosition - b.transform.position).magnitude < 25)
                     {
                         CurrentPart = Instantiate(Parts [b.transform.GetSiblingIndex()]);
                         CurrentPart.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                         foreach (Collider2D c in CurrentPart.GetComponentsInChildren <Collider2D>())
                         {
                             c.enabled = false;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #20
0
    // Update is called once per frame
    void Update()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePos.z = 0;

        if (canPick)
        {
            rayHit.transform.position = mousePos;
        }
        rayHit = Physics2D.Raycast(mousePos, Vector2.zero, 1f, RayHitLayers);

        if (Input.GetMouseButtonDown(0) && rayHit.collider != null && once)
        {
            initPosition = rayHit.transform.position;
            rayName      = rayHit.collider.name;

            if (rayName == "Token_0" || rayName == "Token_1" || rayName == "Token_2" || rayName == "Token_3")
            {
                canPick = true;
                once    = false;
                col1    = rayHit.collider;
                col2    = CharacterManager.instance.currentCharacter.GetComponent <Collider2D>();
            }
            else if (rayName == "Price Bonds" || rayName == "Money Transfer" || rayName == "Share Purchase" || rayName == "Currency Echange")
            {
                canPick = true;
                once    = false;
                col1    = rayHit.collider;
                col2    = monitor.GetComponent <Collider2D>();
            }
            else if (rayName == "1" || rayName == "2" || rayName == "3" || rayName == "4" || rayName == "5" || rayName == "6" || rayName == "7")
            {
                canPick = true;
                once    = false;
                col1    = rayHit.collider;
                col2    = oldCashParent.transform.Find(rayName + rayName).GetComponent <Collider2D>();
            }
            else if (rayName == "Cash")
            {
                canPick = true;
                once    = false;
                col1    = rayHit.collider;
                col2    = CharacterManager.instance.currentCharacter.GetComponent <Collider2D>();
            }
            else if (rayName == "StampReceipt")
            {
                canPick = true;
                once    = false;
                col1    = rayHit.collider;
                col2    = CharacterManager.instance.currentCharacter.GetComponent <Collider2D>();
            }
        }

        if (canPick)
        {
            if (Physics2D.IsTouching(col1, col2) && Input.GetMouseButtonUp(0))
            {
                AudioController.instance.PlayDragSuccessSound();
                col1.gameObject.SetActive(false);
                canPick = false;
                once    = true;
                HideHand();
                if (rayName == "Token_0" || rayName == "Token_1" || rayName == "Token_2" || rayName == "Token_3")
                {
                    StartCoroutine(CharacterManager.instance.MoveCharacterReverse());
                    col1.transform.localPosition = Vector3.zero;
                    canPick = false;
                    once    = true;

                    RatingSystem.instance.ShowNewStarEffect();
                }
                else if (rayName == "Price Bonds" || rayName == "Money Transfer" || rayName == "Share Purchase" || rayName == "Currency Echange")
                {
                    col1.gameObject.SetActive(false);
                    col1.transform.localPosition = Vector3.zero;
                    canPick = false;
                    once    = true;
                    ActivateReceipt(rayHit.collider.gameObject);
                }
                else if (rayName == "StampReceipt")
                {
                    RatingSystem.instance.ShowStarEffect();
                    col1.transform.gameObject.SetActive(false);
                    col1.transform.position = initPosition;
                    canPick = false;
                    once    = true;
                    //StartCoroutine(CharacterManager.instance.MoveCharToIdle());
                    StartCoroutine(CharacterManager.instance.CheckIsOperationsComplete(CharacterManager.currentKey, currentReceipt.name));
                }
                else if (rayName == "1" || rayName == "2" || rayName == "3" || rayName == "4" || rayName == "5" || rayName == "6" || rayName == "7")
                {
                    col1.gameObject.SetActive(false);
                    col1.transform.localPosition = Vector3.zero;
                    canPick = false;
                    once    = true;
                    cashCount++;
                    newCashParent.transform.GetChild(cashCount).GetComponent <Collider2D>().enabled = true;

                    if (cashCount < noOfCash)
                    {
                        string _nm = newCashParent.transform.GetChild(cashCount).name;
                        AnimateHand(newCashParent.transform.GetChild(cashCount).position, oldCashParent.transform.Find(_nm + _nm).position);
                    }

                    if (cashCount >= noOfCash)
                    {
                        cashCount = 0;
                        noOfCash  = 0;
                        print("Cash arranged");

                        if (currentReceipt.name != "Share Purchase")
                        {
                            cash.SetActive(true);
                            InGameUIManager.instance.cashArrangement.SetActive(false);
                            cash.GetComponent <Collider2D>().enabled = true;
                            StartCoroutine(AddDelay(cash.transform.position, CharacterManager.instance.currentCharacter.transform.position, 0.1f));
                        }
                        else
                        {
                            InGameUIManager.instance.cashArrangement.SetActive(false);
                            shareReceipt.SetActive(true);
                            StartCoroutine(AddDelay(shareReceipt.transform.position, CharacterManager.instance.currentCharacter.transform.position, 1f));
                            stamp.SetBool("stamp", true);
                            Invoke("StampBackAnim", 1f);
                        }
                    }
                }
                else if (rayName == "Cash")
                {
                    RatingSystem.instance.ShowStarEffect();
                    cash.GetComponent <Collider2D>().enabled = false;
                    col1.transform.gameObject.SetActive(false);
                    col1.transform.position = new  Vector3(0f, -3.15f, 0f);
                    canPick = false;
                    once    = true;
                    //StartCoroutine(CharacterManager.instance.MoveCharToIdle());
                    StartCoroutine(CharacterManager.instance.CheckIsOperationsComplete(CharacterManager.currentKey, currentReceipt.name));
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                if (rayHit.collider != null)
                {
                    AudioController.instance.PlayDragFailSound();
                    col1.transform.position = initPosition;
                    canPick = false;
                    once    = true;
                }
            }
        }
    }
コード例 #21
0
    // Update is called once per frame
    void Update()
    {
        GetComponent <Rigidbody2D>().WakeUp();


        Vector3 mp = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
                                                                Input.mousePosition.y, Camera.main.nearClipPlane));

        mp.z = 0;

        /*
         * if (Input.GetMouseButtonDown(1))
         * {
         *  if (coll.OverlapPoint(mp))
         *  {
         *      superShrinkReaction();
         *  }
         * }*/


        float td = Time.deltaTime;

        float   curSize   = transform.localScale.x;
        Vector3 globScale = transform.lossyScale;

        //print(curSize);
        if (superShrink)
        {
            //superShrinkReaction();
            transform.localScale = new Vector3(curSize - td * 0.3f, curSize - td * 0.3f);
            Color curCol = rend.color;
            rend.color = new Color(curCol.r - 0.01f, curCol.g, curCol.b, curCol.a);
        }
        else if (curSize < maxSize)
        {
            transform.localScale = new Vector3(curSize + td * eng.growRate, curSize + td * eng.growRate);
        }

        if (curSize < 0)
        {
            Destroy(this.gameObject);
            return;
        }

        if (curSize > 2)
        {
            nextSpawn -= td;
        }

        if (nextSpawn < 0 && maxCreate > 0 && eng.totalGrowth < 80)
        {
            Vector3 rndVec = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0);
            rndVec.Normalize();
            rndVec *= 6;

            Vector3 dir = (rndVec - transform.position);
            dir.Normalize();


            dir *= globScale.x * Random.Range(0.4f, 0.5f);
            if ((transform.position + rndVec).magnitude < 6)
            {
                GameObject newGrowth = Instantiate(eng.growthPrefab, transform.position + dir, new Quaternion());

                newGrowth.transform.localScale = new Vector3(0.01f, 0.01f, 1);

                //Color rndCol = new Color(Random.Range(0.7f, 1f), Random.Range(0.3f, 0.7f), Random.Range(0.3f, 0.7f), 1);
                newGrowth.GetComponent <SpriteRenderer>().color = rend.color;

                newGrowth.GetComponent <Growth>().maxSize = Random.Range(1.5f, 3);

                nextSpawn = 6 * (0.1f / eng.growRate);
                maxCreate--;
                eng.lastGrowthSpawn = 0;
            }
        }


        Core core = FindObjectOfType <Core>();

        if (Physics2D.IsTouching(coll, core.GetComponent <Collider2D>()))
        {
            core.power -= Time.deltaTime * 10;
            FindObjectOfType <MainCamera>().shake += 0.01f;
        }

        Lazer lazer = FindObjectOfType <Lazer>();

        if (lazer != null)
        {
            if (Physics2D.IsTouching(coll, lazer.GetComponent <Collider2D>()))
            {
                superShrinkReaction();
            }
        }
    }
コード例 #22
0
    //Called every frame
    void FixedUpdate()
    {
        if (target != null)
        {
            if (Vector2.Distance(transform.position, target.position) < AggroDistance && Vector2.Distance(transform.position, target.position) > AttackDistance && Chase && timer2 == 0)
            {
                transform.position = Vector2.MoveTowards(transform.position, new Vector2(target.position.x, transform.position.y), speed * Time.deltaTime);
                Anim.SetFloat("speed", 1);
            }
            else if (Vector2.Distance(transform.position, target.position) < 50)
            {
                Anim.SetFloat("speed", 0);
                if (timer == 0)
                {
                    Attack();
                }
            }

            if (transform.position.x > target.position.x && FacingRight && CanFlip)
            {
                Flip();
            }

            if (transform.position.x < target.position.x && !FacingRight && CanFlip)
            {
                Flip();
            }
        }
        else if (target == null)
        {
            Chase = false;
            Anim.SetBool("Attacking", false);
            Anim.SetBool("Attacking2", false);
            Anim.SetBool("Attacking3", false);
            CanFlip     = false;
            SprintLeft  = false;
            SprintRight = false;
            Rb.velocity = new Vector2(0, 0);
        }

        if (SprintRight)
        {
            Rb.velocity = new Vector2(330, Rb.velocity.y);
        }
        else if (SprintLeft)
        {
            Rb.velocity = new Vector2(-330, Rb.velocity.y);
        }
        else
        {
            Rb.velocity = new Vector2(0, Rb.velocity.y);
        }

        if (Physics2D.IsTouching(Character.Instance.weaponCollider, coll) && PlayerController.Instance.CanCollide)
        {
            Physics2D.IgnoreLayerCollision(9, 10, true);
            TakeDamage();
        }

        if (Physics2D.IsTouching(weaponColl, Character.Instance.playerCollider))
        {
            Physics2D.IgnoreLayerCollision(0, 11, true);
            Physics2D.IgnoreLayerCollision(11, 12, true);
            StatsSystem.Instance.TakeDamage(PhysicDamage);
        }
        else if (Physics2D.IsTouching(weaponColl, Character.Instance.shieldCollider))
        {
            Physics2D.IgnoreLayerCollision(0, 11, true);
            Physics2D.IgnoreLayerCollision(11, 12, true);
            StatsSystem.Instance.ShieldTakeDamage(PhysicDamage);
        }
    }
コード例 #23
0
 public bool IsTouchingFloor()
 {
     return(Physics2D.IsTouching(selfCollider, FloorTrigger));
 }
コード例 #24
0
    void Shoot()
    {
        RaycastHit2D hit;
        Ray          ray = new Ray(shotSpawn.position, -shotSpawn.transform.up);

        hit = Physics2D.Raycast(shotSpawn.position, -shotSpawn.transform.up, Vector2.Distance(shotEnd.position, shotSpawn.position), handMask);
        //
        if ((hit.collider != null) && (hit.collider.gameObject.name == "Hand"))
        {
            shotEnd.position = hit.point;
        }
        else
        if ((hit.collider != null) && (hit.collider.gameObject.name == "Monster"))
        {
            shotEnd.position = hit.point;
            hit.collider.gameObject.GetComponent <MonsterReaction>().GetHit();
        }
        //Debug.Log(hit.collider);
        lineRenderer.enabled = true;
        lineRenderer.SetVertexCount(2);
        lineRenderer.SetPosition(0, shotSpawn.position);
        lineRenderer.SetPosition(1, shotEnd.position);
        Rigidbody2D rb2 = shotEnd.GetComponent <Rigidbody2D>();

        if ((Vector2.Distance(shotEnd.position, shotSpawn.position) < shotRange) && (!Physics2D.IsTouching(shotCollider, handCollider)))
        {
            rb2.velocity = -shotEnd.transform.up * shotSpeed;
            //shotEnd.transform.Translate(-shotEnd.transform.up * Time.deltaTime*shotSpeed);
        }
        else
        {
            shotAnim.SetBool("Smoke", true);
            rb2.velocity = Vector2.zero;
        }

        //Debug.Log(rb2.velocity);
    }
コード例 #25
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (hp == 0)
        {
            bossFinish = true;
            greenBird.GetComponent <Rigidbody2D>().gravityScale = 1;
            greenBird.GetComponent <Rigidbody2D>().constraints  = RigidbodyConstraints2D.None;
            exitDoor.position = Vector2.MoveTowards(exitDoor.position, target, 1);
        }

        if (Physics2D.IsTouching(player.GetComponent <BoxCollider2D>(), boss_Cloud))
        {
            bossStart = true;
        }

        if (bossStart && !bossFinish)
        {
            if (greenBird.transform.position.y > 8)
            {
                greenBird.transform.position = Vector2.MoveTowards(greenBird.transform.position, new Vector2(greenBird.transform.position.x, 8.0f), 0.04f);
            }
            else
            {
                if (direction == true && directionCount <= directionMaxCount)
                {
                    greenBird.transform.Translate(Vector3.left * speed * Time.deltaTime);
                    directionCount++;
                }
                else if (direction == false && directionCount <= directionMaxCount)
                {
                    greenBird.transform.Translate(Vector3.right * speed * Time.deltaTime);
                    directionCount++;
                }
                else
                {
                    directionCount = 0;
                    if (direction == true)
                    {
                        direction = false;
                        greenBird.transform.localScale = new Vector3(-4, 4, 1);
                    }
                    else
                    {
                        direction = true;
                        greenBird.transform.localScale = new Vector3(4, 4, 1);
                    }
                }

                if (spawnCount == 0)
                {
                    CreateObject();
                    spawnCount++;
                }
                else
                {
                    if (spawnCount < spawnMaxCount)
                    {
                        spawnCount++;
                    }
                    else
                    {
                        spawnCount = 0;
                    }
                }
            }
            Physics2D.IgnoreCollision(greenBird.GetComponent <CircleCollider2D>(), GameObject.Find("Floor").GetComponent <BoxCollider2D>());
        }
    }
コード例 #26
0
 void CheckPlayer()
 {
     isPlayer = Physics2D.IsTouching(plant, player);
 }
コード例 #27
0
ファイル: Player.cs プロジェクト: jtomelin/BobWorley
 private bool IsGrounded()
 {
     return(Physics2D.IsTouching(GetComponent <CapsuleCollider2D>(), ground.GetComponent <TilemapCollider2D>()));
 }
コード例 #28
0
ファイル: Bullet.cs プロジェクト: OIIOIIOI/CNXProto01
    void FixedUpdate()
    {
        if (destroyWhenOutOfView)
        {
            Vector3 screenPoint = Camera.main.WorldToViewportPoint(transform.position);
            bool    onScreen    = screenPoint.z > 0 &&
                                  screenPoint.x > -0.01f &&
                                  screenPoint.x <1 + 0.01f &&
                                                 screenPoint.y> -0.01f &&
                                  screenPoint.y < 1 + 0.01f;
            if (!onScreen)
            {
                Destroy(this.gameObject);
            }
        }

        if (timeBeforeAutodestruct > 0f)
        {
            timer += Time.deltaTime;
            if (timer > timeBeforeAutodestruct)
            {
                Destroy(this.gameObject);
            }
        }

        if (alive && Physics2D.IsTouching(bulletCollider, contactFilter))
        {
            Collider2D[] targets = new Collider2D[1];
            Physics2D.GetContacts(bulletCollider, contactFilter, targets);
            if (targets.Length > 0)
            {
                Collider2D coll = targets[0];
                switch (coll.tag)
                {
                case "Player":
                    //Debug.Log("hit player");
                    break;

                case "Enemy":
                    //Debug.Log("hit enemy");
                    HealthLife hl = coll.gameObject.GetComponent <HealthLife>();
                    if (hl != null)
                    {
                        hl.TakeHit(damage);
                    }
                    break;

                default:
                    break;
                }
            }

            alive = false;

            bulletCollider.enabled = false;
            spriteRenderer.enabled = false;

            if (particles != null)
            {
                particles.Play();
            }

            Invoke("DieForReal", 2f);
        }
    }