Beispiel #1
0
    IEnumerator DoRunTimer()
    {
        animator.speed = 1 / maxTime;
        animator.SetBool(timerHash, true);

        // Wait a frame to allow animator to transition
        yield return(null);

        float i     = 0;
        float len   = animator.GetCurrentAnimatorStateInfo(0).length;
        var   frame = new WaitForEndOfFrame();

        while (i < len)
        {
            i += Time.deltaTime;
            if (finishOptions == true)
            {
                break;
            }
            yield return(frame);
        }

        // if timer ran out, select either the currently highlighted or first
        if (!finishOptions)
        {
            GameObject currentSelected = EventSystem.current.currentSelectedGameObject;
            if (currentSelected?.CompareTag("Options") == true)
            {
                ClickButton(currentSelected);
            }
            else
            {
                ClickButton(optionButtons[0].gameObject);
            }
        }

        // clean up animator
        animator.speed = 1;
        animator.SetBool(timerHash, false);
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        //if (Input.GetButtonDown("Fire1")) {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (touch.phase == TouchPhase.Began)
            {
                Ray ray = Camera.main.ScreenPointToRay(touch.position);
                //RaycastHit hit;

                if (Physics.Raycast(ray, out RaycastHit hit))
                {
                    GameObject gameObject = hit.collider.gameObject;
                    CardScript hittenCard = gameObject.GetComponent <CardScript>();
                    if (gameObject.CompareTag("Card") && isActive && !hittenCard.IsStateUp)
                    {
                        TapCard(hittenCard);
                    }
                }
            }
        }
    }
Beispiel #3
0
    private bool tryKill(int zPos, int xPos, int thisNote)
    {
        GameObject thisObject = TheSpawnManagerInstance.checkGroundInfo(zPos, xPos);

        if ((thisObject != null) && (thisObject.CompareTag("Enemy")))
        {
            if (TheSpawnManagerInstance.checkGroundNote(zPos, xPos) != thisNote)
            {
                return(false);
            }

            ParticleSystem expParticle = Instantiate(explosionParticle, thisObject.transform.position, explosionParticle.gameObject.transform.rotation);
            // expParticle.Play(); // enabled Play On Awake at prefab
            // the stop action is set to be Destroy at prefab

            TheSpawnManagerInstance.updateGroundInfo(zPos, xPos, null);
            TheSpawnManagerInstance.updateGroundNote(zPos, xPos, -1);
            Destroy(thisObject);
            TheSpawnManagerInstance.updateEnemySum(-1);
            TheSpawnManagerInstance.addScore();
            return(true);
        }
        return(false);
    }
        /// <summary>
        /// Collect data from the detected object if a detectable tag is matched.
        /// </summary>
        internal void ProcessDetectedObject(GameObject detectedObject, int cellIndex)
        {
            Profiler.BeginSample("GridSensor.ProcessDetectedObject");
            for (var i = 0; i < m_DetectableTags.Length; i++)
            {
                if (!ReferenceEquals(detectedObject, null) && detectedObject.CompareTag(m_DetectableTags[i]))
                {
                    if (GetProcessCollidersMethod() == ProcessCollidersMethod.ProcessAllColliders)
                    {
                        Array.Copy(m_PerceptionBuffer, cellIndex * m_CellObservationSize, m_CellDataBuffer, 0, m_CellObservationSize);
                    }
                    else
                    {
                        Array.Clear(m_CellDataBuffer, 0, m_CellDataBuffer.Length);
                    }

                    GetObjectData(detectedObject, i, m_CellDataBuffer);
                    ValidateValues(m_CellDataBuffer, detectedObject);
                    Array.Copy(m_CellDataBuffer, 0, m_PerceptionBuffer, cellIndex * m_CellObservationSize, m_CellObservationSize);
                    break;
                }
            }
            Profiler.EndSample();
        }
Beispiel #5
0
    /// <summary>
    /// Update is called once per frame.
    /// </summary>
    public void Update()
    {
        // Casts ray towards camera's forward direction, to detect if a GameObject is being gazed
        // at.
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, _maxDistance))
        {
            if (_gazedAtObject != hit.transform.gameObject)
            {
                // New GameObject.
                // _gazedAtObject?.SendMessage("OnPointerExit");
                _gazedAtObject = hit.transform.gameObject;

                if ((hit.collider.CompareTag("Weapon") || hit.collider.CompareTag("VirtualButton")) && !_gazedAtObject.CompareTag("Bounds"))
                {
                    _gazedAtObject.SendMessage("OnPointerEnter");
                }
            }
        }
        else
        {
            // No GameObject detected in front of the camera.
            if (_gazedAtObject != null && !_gazedAtObject.CompareTag("Bounds"))
            {
                _gazedAtObject?.SendMessage("OnPointerExit");
            }
            _gazedAtObject = null;
        }

        // Checks for screen touches.
        if (Google.XR.Cardboard.Api.IsTriggerPressed)
        {
            _gazedAtObject?.SendMessage("OnPointerClick");
        }
    }
Beispiel #6
0
    public static T[] GetExtComponentsInParentsWithTagAndLayer <T>(this GameObject gameObject, string tag, LayerMask layer, int depth = 99, bool startWithOurself = false)
        where T : Component
    {
        List <T> results = new List <T>();

        if (startWithOurself && gameObject.layer == layer && gameObject.CompareTag(tag))
        {
            T[] allComponentOfThisGameObject = gameObject.GetComponents <T>();
            for (int i = 0; i < allComponentOfThisGameObject.Length; i++)
            {
                results.Add(allComponentOfThisGameObject[i]);
            }
        }
        Transform firstParent = gameObject.transform.parent;

        int currentDepth = 0;

        for (Transform t = firstParent; t != null; t = t.parent)
        {
            if (t.gameObject.layer == layer && t.CompareTag(tag))
            {
                T[] allComponentOfThisGameObject = t.GetComponents <T>();
                for (int i = 0; i < allComponentOfThisGameObject.Length; i++)
                {
                    results.Add(allComponentOfThisGameObject[i]);
                }
            }
            currentDepth++;
            if (currentDepth >= depth)
            {
                break;
            }
        }

        return(results.ToArray());
    }
    // Update is called once per frame
    void Update()
    {
        float tY, tX = 0;

        tY = Time.time * scrollingSpeed % _panelHeight + (_panelHeight * 0.5f);

        // additional logic added to allow for star movement on any scene, even without the player - note that the 'player' item must be assigned in the inspector - however, if it is an object without the 'Hero' tag, this will not run.
        if (player != null && player.CompareTag("Hero"))
        {
            // player != null logic comes before the CompareTag function call - if the first term evaluates false, then comparetag will not try and find the tag of an object that does not exist. && operator only evaluates the second condition in the event the first one is true.
            tX = -player.transform.position.x * motionMult;
        }

        panels[0].transform.position = new Vector3(tX, tY, _panelDepth);

        if (tY >= 0)
        {
            panels[1].transform.position = new Vector3(tX, tY - _panelHeight, _panelDepth);
        }
        else
        {
            panels[1].transform.position = new Vector3(tX, tY + _panelHeight, _panelDepth);
        }
    }
    // Проверяет наличие тега "Player" у данного объекта и
    // вызывает UnityEvent, если такой тег имеется.
    void SendSignal(GameObject objectThatHit)
    {
        // Объект отмечен тегом "Player"?
        if (objectThatHit.CompareTag("Player"))
        {
            // Если требуется воспроизвести звук, попытаться сделать это
            if (playAudioOnTouch)
            {
                var audio = GetComponent <AudioSource>();

                // Если имеется аудиокомпонент
                // и родитель этого компонента активен,
                // воспроизвести звук
                if (audio &&
                    audio.gameObject.activeInHierarchy)
                {
                    audio.Play();
                }
            }

            // Вызвать событие
            onTouch.Invoke();
        }
    }
 private void IsCamerPoint(GameObject obj)
 {
     if (obj != null && obj.CompareTag("cameraPoint") && m_otherCameraDic.ContainsKey(obj))
     {
         EngineCoreEvents.AudioEvents.PlayAudio.SafeInvoke(Audio.AudioType.UISound, GameCustomAudioKey.zoom_in.ToString());
         GameEvents.SceneEvents.SetSceneType.SafeInvoke(1);
         GameEvents.MainGameEvents.OnFingerForbidden.SafeInvoke(true);
         this.m_forbiddenTouch  = true;
         this.m_quitObj.Visible = false;
         GameEvents.MainGameEvents.OnForbidProp.SafeInvoke(-1, true);
         this.m_currentOtherCamera = m_otherCameraDic[obj];
         HideOrShowOtherCamera(false);
         m_otherCameraDic[obj].PlayCameraTween(this.m_mainCameraTran.gameObject, (SceneCameraParams_New cameraParams, bool canZoom, string cameraName) => {
             this.m_btnBack.Visible = true;
             this.m_quitObj.Visible = true;
             this.m_currentCamera   = cameraName;
             this.m_mainCamera.SetSceneCameraParam(cameraParams);
             this.m_mainCamera.SetCanZoom(canZoom);
             GameEvents.MainGameEvents.OnFingerForbidden.SafeInvoke(false);
             GameEvents.MainGameEvents.OnForbidProp.SafeInvoke(-1, false);
             this.m_forbiddenTouch = false;
         });
     }
 }
Beispiel #10
0
 void CheckMatches()
 {
     if (column > 0 && column < grid.gridSizeX - 1)
     {
         GameObject leftTile  = grid.tiles[column - 1, row];
         GameObject rightTile = grid.tiles[column + 1, row];
         if (leftTile != null && rightTile != null)
         {
             if (leftTile.CompareTag(gameObject.tag) && rightTile.CompareTag(gameObject.tag))
             {
                 isMatched = true;
                 rightTile.GetComponent <Tile>().isMatched = true;
                 leftTile.GetComponent <Tile>().isMatched  = true;
             }
         }
     }
     if (row > 0 && row < grid.gridSizeY - 1)
     {
         GameObject upTile   = grid.tiles[column, row + 1];
         GameObject downTile = grid.tiles[column, row - 1];
         if (upTile != null && downTile != null)
         {
             if (upTile.CompareTag(gameObject.tag) && downTile.CompareTag(gameObject.tag))
             {
                 isMatched = true;
                 downTile.GetComponent <Tile>().isMatched = true;
                 upTile.GetComponent <Tile>().isMatched   = true;
             }
         }
     }
     if (isMatched)
     {
         SpriteRenderer sprite = GetComponent <SpriteRenderer>();
         sprite.color = Color.grey;
     }
 }
Beispiel #11
0
    public void ResolveCollision(GameObject go, Collision2D collision)
    {
        if (!isPlaying)
        {
            return;
        }

        if (go.CompareTag("Player"))
        {
            var player = go.GetComponent <Player>();
            if (collision.collider.CompareTag("Object"))
            {
                var objectColorScript = collision.gameObject.GetComponent <ColorScript>();
                var objectScript      = collision.gameObject.GetComponent <ObjectInLevel>();
                lastObjectPos = collision.transform.position;
                if (player.colorScript.ColorName == objectColorScript.ColorName)
                {
                    // Collect

                    bonusScore += objectScript.BonusAmount();

                    OnScoreChange(CurrentScore);
                    objectScript.Collect();
                    SoundManager.instance.PlaySound(Storage.instance.collectSound);
                }
                else
                {
                    objectScript.CollideAsEnemy();
                    if (player.IsMortal)
                    {
                        Lose();
                    }
                }
            }
        }
    }
    internal virtual void SpawnEnemy()
    {
        if (currentTile == null)
        {
            return;
        }
        if (assetSpawner == null)
        {
            return;
        }

        try
        {
            GameObject go = assetSpawner.SpawnAssetGeneric(
                asset: agentToSpawn,                            //the agent we want to spawn into the world
                assetName: agentToSpawn.name,                   //the name of the agent, e.g: skeleton
                t: currentTile,                                 //the current tile the thing this is attached to is on
                spawnOntoRandomTileNeighbour: true              //whether we want this object to spawn automagically onto a randomly selected neighbour tile
                );

            if (!go.CompareTag("Enemy"))
            {
                go.tag = "Enemy";
            }
            Tile goT = go.GetComponent <Tile>();
            goT.Type = Tile.TileType.Enemy;
            Agents.Agent      spawnedAgent = go.GetComponent <Agents.Agent>();
            AISuperSimpleMove aiMover      = go.AddComponent <AISuperSimpleMove>();
            spawnedAgent.Init(agentConfig, aiMover);
            aiMover.Init(spawnedAgent, agentConfig, go.transform.parent.GetComponent <Tile>());
            TurnManagement.AgentTurnSetter.AddAgentToStateMachine(spawnedAgent);
            amountOfAgentsSpawned++;
            go.name += $" ({amountOfAgentsSpawned})";
        }
        catch { /*please don't do what I'm doing here*/ }
    }
Beispiel #13
0
    internal void CheckHits()
    {
        RaycastHit hitInfo;

        if (Physics.Raycast(new Ray(Position, Forward), out hitInfo))
        {
            var hitObject = hitInfo.transform.gameObject;
            if (hitObject != lastCollided)
            {
                prevCollided = lastCollided;
                lastCollided = hitInfo.transform.parent != null ? hitInfo.transform.parent.gameObject : hitInfo.transform.gameObject;

                if (lastCollided.CompareTag(ViveManipulable.Highlightable))
                {
                    CollidedHighlighter = hitInfo.transform.name;
                }
                else
                {
                    CollidedName        = hitInfo.transform.name;
                    CollidedHighlighter = string.Empty;
                }
            }
        }
        else
        {
            if (lastCollided != null)
            {
                prevCollided        = lastCollided;
                CollidedName        = string.Empty;
                CollidedHighlighter = string.Empty;
                lastCollided        = null;
            }
        }

        HitPoint = hitInfo.point;
    }
Beispiel #14
0
    public void CollisionEvent(GameObject thisObj, Collision collision)
    {
        // we have to use contact points because otherwise child colliders
        // such as a shield just count as normal collisions
        var contactPoint = collision.contacts [0];

        // only process collision "caused" by the car
        if (contactPoint.thisCollider.gameObject.Equals(thisObj))
        {
            CarController thisCar  = thisObj.GetComponent <CarController>();
            GameObject    otherObj = contactPoint.otherCollider.gameObject;
            if (otherObj.CompareTag("Car"))
            {
                //this is two cars colliding
                CarController otherCar = otherObj.GetComponent <CarController>();
                if (!CarHasShield(thisCar) && !CarHasShield(otherCar) && otherCar.IsTransferTimeExpired() && otherCar.HasBomb)
                {
                    otherCar.setBombAllDevices(!otherCar.HasBomb);
                    thisCar.setBombAllDevices(!thisCar.HasBomb);
                    thisCar.UpdateTransferTime(1.0f);
                }
            }
        }
    }
Beispiel #15
0
 public static Ability GetAbility(string abilityName, GameObject user)
 {
     if (user.transform.CompareTag("Player"))
     {
         foreach (Ability a in PlayerInformation.Abilities)
         {
             if (a.Name == abilityName)
             {
                 return(a);
             }
         }
     }
     else if (user.CompareTag("Enemy"))
     {
         foreach (Ability a in user.GetComponent <Enemy>().Abilities)
         {
             if (a.Name == abilityName)
             {
                 return(a);
             }
         }
     }
     return(null);
 }
Beispiel #16
0
    void Spawn()
    {
        if (nextTimeToSearch <= Time.time)
        {
            Vector3 playerVelocity      = player.GetComponent <Rigidbody2D> ().velocity;
            float   playerVeloMagnitude = playerVelocity.magnitude;

            closestPlanet = gc.getClosestPlanet(this.gameObject.transform.position);
            if (playerVeloMagnitude > spawnSpeedThreshold && !closestPlanet.CompareTag("Earth"))
            {
                Vector3 playerVeloNormalized = playerVelocity.normalized;
                float   x          = player.transform.position.x + (playerVeloNormalized.x * spawnDistance) + Random.Range(-1 * spawnRadius, spawnRadius);
                float   y          = player.transform.position.y + (playerVeloNormalized.y * spawnDistance) + Random.Range(-1 * spawnRadius, spawnRadius);;
                Vector3 newItemPos = new Vector3(x, y, 0);

                GameObject newItem = Instantiate(item);

                float widthMultiplier = Random.Range(1, maxSpawnSizeMultiplier);
                newItem.transform.localScale = new Vector3(newItem.transform.localScale.x * widthMultiplier, newItem.transform.localScale.y * widthMultiplier, 1);
                newItem.transform.position   = newItemPos;
                nextTimeToSearch             = Time.time + spawnFrequency;
            }
        }
    }
Beispiel #17
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        GameObject other = collider.gameObject;

        if (other.CompareTag("Enemy"))
        {
            Enemy enemy = other.GetComponent <Enemy>();
            enemy.ReceiveDamage(damageValue);
            if (auraType == 1)
            {
                enemy.ReceiveFireDamage(tickLength, tickDamage, totalDuration);
            }
            if (auraType == 2)
            {
                enemy.HandleChillEffect(slowDuration, freezeDuration);
            }
            other.GetComponent <Rigidbody2D>().AddForce(
                new Vector2(
                    other.transform.position.x - transform.position.x
                    , other.transform.position.y - transform.position.y
                    ).normalized *other.GetComponent <Rigidbody2D>().mass * 100);    //Edit by Bill
            Debug.Log("hit enemy, Damage = " + damageValue);
        }
    }
Beispiel #18
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject collider = collision.gameObject;

        //  Debug.Log(collision.gameObject.tag);
        if (collider.CompareTag("ChainHead"))
        {
            if (collider.transform.parent.
                GetComponent <ChainController>().GetState().Equals("shooting"))
            {
                //    GameObject ChainGroup = collider.transform.parent.gameObject;
                //    ChainGroup.GetComponent<ChainController>().StruckChainable(collider);

                Debug.Log("Chain Detected on Chainable Surface");
            }
        }
        //else if (collider.CompareTag("Player"))
        //{

        //    Debug.Log("Player is touching chainable object");
        //    collider.GetComponent<ArtrobotController>().SetClimbing(true, gameObject);
        //    collider.GetComponent<ArtrobotController>().AimReset();
        //}
    }
    //Checks to see if this object was tagged as Player, and
    //invoke the UnityEvent if it was.
    void SendSignal(GameObject objectThatHit)
    {
        //Was this object tagged Player?
        if (objectThatHit.CompareTag("Player"))
        {
            //If we should play a sound, attempt to play it.
            if (playAudioOnTouch)
            {
                var audio = GetComponent <AudioSource>();

                //If we have an audio component,
                //and this component's parents
                //are active, then play.
                if (audio &&
                    audio.gameObject.activeInHierarchy)
                {
                    audio.Play();
                }
            }

            //Invoke the event.
            onTouch.Invoke();
        }
    }
Beispiel #20
0
    void OnTriggerEnter(Collider collider)
    {
        Atom atom = collider.gameObject.GetComponent <Atom>();

        if (atom != null && Arranger.HasEmptyLinks && atom.Arranger.HasEmptyLinks)
        {
            System.Random random = new System.Random();
            P = random.Next();
            while (P == atom.P)
            {
                P = random.Next();
            }
            if (P > atom.P)
            {
                Debug.Log($"{name} linked with {atom.name}");
                P = null;
                Arranger.Link(atom.transform);
                atom.RotateTowards(transform);
            }
            P      = null;
            moving = false;
            return;
        }

        GameObject col = collider.gameObject;

        if (col.CompareTag("Wall"))
        {
            Transform wall = col.transform;
            float     x    = col.name.Equals("Right") || col.name.Equals("Left") ? -Movement.x : Movement.x;
            float     y    = col.name.Equals("Top") || col.name.Equals("Bottom") ? -Movement.y : Movement.y;
            float     z    = col.name.Equals("Back") || col.name.Equals("Front") ? -Movement.z : Movement.z;

            Movement = new Vector3(x, y, z);
        }
    }
Beispiel #21
0
    void spawnStep()
    {
        GameObject newPrint = printPool.getNextPrint();

        if (!newPrint.CompareTag("spawned"))
        {
            newPrint     = Instantiate(newPrint);
            newPrint.tag = "spawned";
            printPool.registerPrint(newPrint);
        }
        newPrint.transform.SetParent(transform);
        if (foot)
        {
            newPrint.transform.localPosition = new Vector3(-printOffset, surfDist, 0);
        }
        else
        {
            newPrint.transform.localPosition = new Vector3(printOffset, surfDist, 0);
        }
        newPrint.transform.rotation = transform.rotation;
        newPrint.GetComponent <AkAmbient>().triggered(); // PLAY AUDIO
        newPrint.transform.SetParent(null);
        foot = !foot;
    }
Beispiel #22
0
    ////Collisions
    public void OnCollisionEnter(Collision collision)
    {
        GameObject itemToCheck = collision.collider.gameObject;

        ////Healing
        ///Item collides with carriage
        if (itemToCheck.CompareTag("Item"))
        {
            if (currentItemRequired == itemToCheck.GetComponent <itemInfo>().ID)
            {
                Destroy(itemToCheck);
                health = maxHealth;

                //Chooses new item
                selectNewItem();
            }
        }


        ///Player collides with carriage while player is holding item
        if (collision.gameObject.tag == "Player")
        {
            print(collision.gameObject.GetComponent <playerMovementScript>().itemHeld.GetComponent <itemInfo>().ID);

            print(currentItemRequired);

            if (currentItemRequired == collision.gameObject.GetComponent <playerMovementScript>().itemHeld.GetComponent <itemInfo>().ID)
            {
                Destroy(itemToCheck.GetComponent <playerMovementScript>().itemHeld);
                health = maxHealth;

                //Chooses new item
                selectNewItem();
            }
        }
    }
Beispiel #23
0
    // changes the target and sets insect color
    void ChangeTarget(GameObject target)
    {
        // clear old target and set new one
        if (targetPlant.CompareTag("plant"))
        {
            targetPlant.GetComponent <CirclePlantPrefabScript>().IsTargeted = false;
        }

        if (target != targetPlant)
        {
            Comment("New target: {0}", target);
        }
        targetPlant = target;
        // then colorize insect based on target
        // white=null, green=plant, yellow=tree+full, orange=tree+unfull, red=tree+empty
        if (targetPlant == null)
        {
            renderer.material.color = Color.white;
        }
        else if (targetPlant.CompareTag("plant"))
        {
            renderer.material.color = Color.green;
            targetPlant.GetComponent <CirclePlantPrefabScript>().IsTargeted = true;
        }
        else if (targetPlant.CompareTag("tree"))
        {
            if (pollen > 0)
            {
                renderer.material.color = pollen < pollenCapacity?Color.Lerp(Color.red, Color.yellow, 0.5f) : Color.yellow;
            }
            else
            {
                renderer.material.color = Color.red;
            }
        }
    }
Beispiel #24
0
 // Update is called once per frame
 void Update()
 {
     if (this.isPossessed && !hm.AnyoneMoving())
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             RaycastHit2D hit = Physics2D.Raycast(this.transform.position +
                                                  new Vector3(currentDir.GetVector().x, currentDir.GetVector().y, 0), currentDir.GetVector());
             if (hit.collider != null)
             {
                 GameObject otherThing = hit.collider.gameObject;
                 if (otherThing.CompareTag("Person") &&
                     otherThing.GetComponent <PlayerController> ().currentDir == this.currentDir.Opposite())
                 {
                     otherThing.GetComponent <PlayerController> ().BecomePossessed();
                 }
             }
         }
         else if (wasMoving)
         {
             wasMoving = false;
         }
     }
 }
Beispiel #25
0
        private void SpawnGameObject(Spawnable spawnable,
                                     GameObject gameObjectInstance,
                                     PositionRotation spawnLocRot,
                                     Vector3 color)
        {
            if (spawnLocRot != null)
            {
                gameObjectInstance.transform.localPosition = spawnLocRot.Position;
                gameObjectInstance.transform.Rotate(spawnLocRot.Rotation);
                gameObjectInstance.SetLayer(0);
                gameObjectInstance.GetComponent <IPrefab>().SetColor(color);

                if (gameObjectInstance.CompareTag("goodGoal"))
                {
                    _goodGoalsMultiSpawned.Add(gameObjectInstance.GetComponent <Goal>());
                }
            }
            else
            {
                // GameObject.DestroyImmediate(gameObjectInstance);
                gameObjectInstance.SetActive(false);
                GameObject.Destroy(gameObjectInstance);
            }
        }
    // highlighting erase function
    public void objectHighlightEraser(GameObject target = null)
    {
        if (target == null)
        {
            return;
        }

        // stackPoint의 경우 SpriteRenderer가 없으므로 target을 parent로 바꾸어줌
        //if (target.GetComponent<SpriteRenderer>() == null)
        if (target.CompareTag("Arrangeable_Stack"))
        {
            target = target.transform.parent.gameObject;
        }

        target.GetComponent <SpriteRenderer>().material = defaultMaterial;
        GameObject tmp = target;

        while (tmp.transform.childCount > 2)
        {
            tmp = tmp.transform.GetChild(2).gameObject; // index

            tmp.GetComponent <SpriteRenderer>().material = defaultMaterial;
        }
    }
    public bool RelocateUnitsPositionOnLists(GameObject selectedUnit, GameObject targetUnit)
    {
        GameObject tempSwapVar;
        int        indexOf_SelectedUnit = 0;
        int        indexOf_TargetUnit   = 0;

        indexOf_SelectedUnit = board.playerBenchList.IndexOf(selectedUnit);
        if (board.playerUnitCount < this.GetComponent <Player>().level&& targetUnit.CompareTag("BoardBlock"))
        {
            indexOf_TargetUnit = board.chessboardPosition.IndexOf(targetUnit);
            if (indexOf_TargetUnit <= 32)
            {
                //Debug.Log(indexOf_SelectedUnit + "     " + indexOf_TargetUnit);
                tempSwapVar = board.playerBenchList[indexOf_SelectedUnit];

                board.playerBoardList[indexOf_TargetUnit] = board.playerBenchList[indexOf_SelectedUnit];
                board.playerBoardList[indexOf_TargetUnit].transform.parent = board.chessboardPosition[indexOf_TargetUnit].transform;
                board.playerBenchList[indexOf_SelectedUnit] = null;
                return(true);
            }
            //Destroy(tempSwapVar);
        }
        return(false);
    }
Beispiel #28
0
        void OnTriggerEnter(Collider other)
        {
            GameObject go = other.gameObject;

            if (go.CompareTag("Player"))
            {
                if (kart.GetComponent <OvershieldPUP>())
                {
                    Debug.Log("Already have an OS, destroying this one");
                    Destroy(kart.GetComponent <OvershieldPUP>());
                }
                // create the new PowerUp
                PowerUp po = kart.gameObject.AddComponent <OvershieldPUP>();
                // if it is the only PowerUp then it should be active
                PowerUp[] pups = kart.gameObject.GetComponents <PowerUp>();
                po.Init();
                po.powerUpGO       = powerUpGO;
                po.kart            = kart;
                po.uses            = uses;
                po.passiveLifetime = passiveLifetime;
                Debug.Log("Destroying!");
                Destroy(gameObject);
            }
        }
Beispiel #29
0
    /// <summary>
    /// If the submit action is performed via anything other than mouse,
    /// click the current selected button
    /// </summary>
    /// <param name="context"></param>
    private void ListenForKeyboard(InputAction.CallbackContext context)
    {
        // Check if cancelled
        if (context.canceled)
        {
            return;
        }

        // Don't allow early keyboard clicks in case we're still in the middle of showing options
        if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime % 1 < KEYBOARD_DELAY * animator.speed)
        {
            return;
        }

        // else, click if current selected is an options button
        if (context.action.name == "Submit" && context.performed && context.control != Mouse.current.leftButton)
        {
            GameObject currentSelected = EventSystem.current.currentSelectedGameObject;
            if (currentSelected?.CompareTag("Options") == true)
            {
                ClickButton(currentSelected);
            }
        }
    }
    /// <summary>
    /// Attempts to attack.
    /// The Player can only attack every timeBetweenAttacks.
    /// There is 12.5% chance that the Player will miss.
    /// The damage is applied to target Enemy health.
    /// </summary>
    private void Attack()
    {
        if (Input.GetMouseButtonDown(0) && (Time.time - timeSinceLastAttack >= timeBetweenAttacks)) // Checks if the button was clicked
        {                                                                                           // and if it is the time to attack
            Debug.Log("Attempt to attack");

            timeSinceLastAttack = Time.time;
            // TODO: Change animation to attack

            GameObject enemy = EnemyClicked(); // Get anything that was clicked on

            if (enemy == null)
            {
                return; // Returns if the enemy is null
            }

            if (enemy.CompareTag("Enemy") && Vector3.Distance(enemy.transform.position, transform.position) <= range) // Checks if the target is an Enemy and is in range
            {
                EnemyHealth enemyHealth = enemy.GetComponent <EnemyHealth>();

                int missValue = Random.Range(0, 8);

                if (missValue != 0)                                                    // Checks if the attack missed
                {
                    float damage = baseDamage + Mathf.Round(Random.Range(3.0f, 7.0f)); // Calculate the damage
                    enemyHealth.ChangeHealthPoints(-damage);

                    playerIntensity.Increase(intensityIncrease); // Increase intensity when hitting an Enemy
                }
                else
                {
                    Debug.Log("Player missed.");
                }
            }
        }
    }
Beispiel #31
0
 public void WeDisregardCasing()
 {
     GameObject go = new GameObject();
     go.tag = "NewTag";
     Assert.That(go.CompareTag("newtag"), Is.True);
 }
Beispiel #32
0
 public void WeWillNotFindOtherTags()
 {
     GameObject go = new GameObject();
     go.tag = "NewTag";
     Assert.That(go.CompareTag("OtherTag"), Is.False);
 }
Beispiel #33
0
 public void WeWillFindACorrectTag()
 {
     GameObject go = new GameObject();
     go.tag = "NewTag";
     Assert.That(go.CompareTag("NewTag"), Is.True);
 }