CompareTag() public method

public CompareTag ( string tag ) : bool
tag string
return bool
Example #1
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;
        }
    }
    public void PossessPlayer(GameObject player)
    {
        if (state == CameraState.FREE_FLOW)
        {
            if (player.CompareTag("Salesman"))
            {
                character = CharacterClass.SALESMAN;
            }
            else if (player.CompareTag("Shopper"))
            {
                character = CharacterClass.SHOPPER;
            }
            else if (player.CompareTag("Guard"))
            {
                character = CharacterClass.GUARD;
            }
            else if (player.CompareTag("Thief"))
            {
                character = CharacterClass.THIEF;
            }
            else return;

            PossessionScript ps = player.GetComponent<PossessionScript>();
            ps.Possess();

            possessedCharacter = player;
            attachedRotation = player.transform.rotation;
            attachedLocation = player.transform.position + attachedRotation * new Vector3(0, 1.85f, -2);
            freeFlyLocation = transform.position;
            freeFlyRotation = transform.rotation;

            state = CameraState.ATTACHING;
            tick = 0;
        }
    }
 public void removeBuild(GameObject obj, bool bank)
 {
     Debug.Log("Removed" + obj.name);
     if (bank)
     {
         banks.Remove(obj);
     }
     else if (obj.CompareTag("RoadBlock"))
     {
         targetCount.GetComponent<TargetMover>().roadBlockCounter -= 1;
         //monster.GetComponent<Attack_Building>().inAction = false;
         buildings.Remove(obj);
         //Debug.Log("Entered");
     }
     else if(obj.CompareTag("PileOFish"))
     {
         targetCount.GetComponent<TargetMover>().PileOFishCounter -= 1;
         //monster.GetComponent<Attack_Building>().inAction = false;
         buildings.Remove(obj);
     }
     else
     {
         buildings.Remove(obj);
     }
 }
Example #4
0
    void OnParticleCollision(GameObject other)
    {
        print("burn!!!!");
		if (other.CompareTag("Torch"))
		{
			ParticleSystem fire = other.GetComponentInChildren<ParticleSystem>();
			fire.Play();
		}
		if (other.CompareTag("Rubble"))
		{
			Debug.Log("boom");
            Rigidbody[] pieces = other.gameObject.GetComponentsInChildren<Rigidbody>();
            foreach (Rigidbody piece in pieces)
            {
                piece.isKinematic = false;
                piece.AddExplosionForce(500, other.gameObject.transform.position, 5);
            }
            BoxCollider goocollider = other.GetComponent<BoxCollider>();
            goocollider.enabled = false;
            ParticleSystem bakahatsu = other.GetComponentInChildren<ParticleSystem>();
            bakahatsu.Play();
            GameObject goo = other.transform.FindChild("Goo").gameObject;
            Destroy(goo);

		}
    }
    private bool IsBorderOrGroundHit(GameObject collidedObject)
    {
        if (collidedObject.CompareTag("Ground") || collidedObject.CompareTag("Border")) {
            DestroyObject(gameObject);
            return true;
        }

        return false;
    }
 public static void HitBrick(GameObject brick)
 {
     if (brick.CompareTag ("Breakable")) {
         BrickController bc = brick.GetComponent<BrickController>();
         bc.handleHits();
     }
 }
    public void StartSpeech(GameObject initiator)
    {
        if (showingText)
        {
            return;
        }

        if (randomizeTexts)
        {
            textIndex = Random.Range(0, texts.Length - 1);
        }

        if (initiator.CompareTag(playerTag))
        {
            playerControl = initiator.GetComponent<PlayerControl>();
            playerControl.freezeInput = true;
            speech.SetActive(true);

            showingText = true;
            skipUpdate = true;
            textAdvancer = initiator.GetComponent<TextAdvancer>();

            DrawText();
        }
    }
Example #8
0
 public void StopContactBottom(GameObject other)
 {
     if (other.CompareTag("Platform") && contactingPlatforms.Contains(other))
     {
         contactingPlatforms.Remove(other);
     }
 }
 bool ignoreCheck(GameObject obj)
 {
     foreach (string tag in m_IgnoreTags)
         if (obj.CompareTag(tag))
             return true;
     return false;
 }
Example #10
0
    /**
     * Check to see if their is los to marines target
     **/
    public bool CanHitTarget(GameObject marineShooter, GameObject target)
    {
        // exit if marine isn't shooting an alien
        if(marineShooter == null ||  !target.CompareTag("Alien"))
            return false;

        // exit if the alien is already dead
        if(target.GetComponent<AlienData>().unitStatus == AlienData.UnitStatus.DEAD)
            return false;

        RaycastHit hit;

        Vector3 targetVector = target.transform.position;
        targetVector.y = marineShooter.transform.position.y;
        Vector3 rayDirection = targetVector - marineShooter.transform.position;
        _debug_source_trans = marineShooter.transform;
        _debug_target = rayDirection;

           	 	if (Physics.Raycast (marineShooter.transform.position, rayDirection, out hit)) {

            if (hit.transform.gameObject.CompareTag("Alien")) {
                Debug.Log("i see my target!");
                return true;
            } else {
                // there is something obstructing the view
                Debug.Log("i CANT see my target!");
                GetComponentInChildren<GUIManager>().StatusMessageText = "No line of sight.";
                return false;
            }

        }
        Debug.Log("no ray collision on shot");

        return false;
    }
Example #11
0
 void OnParticleCollision(GameObject obj)
 {
     if (obj.CompareTag("Bat"))
     {
         Debug.Log ("hit!");
     }
 }
Example #12
0
 void OnParticleCollision(GameObject other)
 {
     if (other.CompareTag("Rain"))
     {
         isHitByRain = true;
     }
 }
	private void TryDealDamage( GameObject victim )
	{
		// Check that the victim can take damage
		ObjectHealthScript healthhandle = victim.GetComponent<ObjectHealthScript>();
		if ( healthhandle )
		{
			// Isn't on the same team
			if ( !victim.CompareTag( TeamTag ) )
			{
				// Can damage currently
				if ( NextDamage <= Time.time )
				{
					healthhandle.TakeHealth( Damage );

					// Delay before next damage to any victim
					NextDamage = Time.time + BetweenDamage;

                    // Destroy if it was a one shot
                    if ( OneShot )
                    {
                        Destroy( this );
                    }
				}
			}
		}
	}
Example #14
0
    private void Spawn()
    {
        GameObject lastPiece = this.nextPiece;
        if (lastPiece == null)
        {
            // we didn't have the next piece ready (first run), so create one manually
            int lastIndex = Random.Range (0, this.pieces.Length);
            lastPiece = Instantiate<GameObject> (pieces [lastIndex]);
            lastPiece.GetComponent<Tetrimino>().gameController = gameController;
        }

        lastPiece.transform.position = new Vector2();
        lastPiece.GetComponent<Tetrimino>().enabled = true;

        int index = Random.Range (0, this.pieces.Length);
        // we need to generate a new piece, but not the same as the last one
        nextPiece = Instantiate<GameObject>(pieces[index]);
        while(nextPiece.CompareTag(lastPiece.tag)) {
            DestroyImmediate(nextPiece);
            nextPiece = Instantiate<GameObject>(pieces[index]);
        }

        Tetrimino nextTetrimino = nextPiece.GetComponent<Tetrimino>();
        nextTetrimino.gameController = gameController;
        nextTetrimino.enabled = false;
    }
Example #15
0
 static void RenderLightGizmo(GameObject gameObject, GizmoType gizmoType)
 {
     if (gameObject.CompareTag("SpawnPoint")) {
         Gizmos.color = Color.red;
         Gizmos.DrawSphere(gameObject.transform.position, 0.5f);
     }
 }
Example #16
0
    private void checkObjectDrag(GameObject hit)
    {
        if (hit.CompareTag("Key") && hit.name != curChar)
        {
            if (duration != 0) //don't sent first time
                swypeController.AddCharacter(curChar[0], duration);//send previous character

            curChar = hit.name;
            duration = 0;
            //swypeController.AddCharacter(curChar[0]);
        }
        if (hit.CompareTag("Key") && hit.name == curChar)
            duration += Time.deltaTime;
        if(partOfKeyBoard(hit))
            painter.addPoint(fingerTipPos);
    }
Example #17
0
    //-------------------------------------------------------------------------
    public void SetTarget(GameObject newTarget)
    {
		if (newTarget.CompareTag ("Player")) {
			Debug.Log ("Player Detected");
			target = newTarget.transform;
		}
    }
Example #18
0
	// Update is called once per frame
	void Update () {

		if (UICamera.GetMouse (0).pressStarted) {
			currentClicked = UICamera.GetMouse (0).pressed;
			if(Kontext.gameObject.activeSelf){
				if (currentClicked != null && (currentClicked.transform.IsChildOf (transform) || currentClicked.CompareTag ("Robot")))
					NGUITools.SetActiveChildren (gameObject, true);
				else {
					Kontext.Close ();
					NGUITools.SetActiveChildren (gameObject, false);
				}
			}
		}

		if (UICamera.GetMouse (1).pressStarted) {
			currentClicked = UICamera.GetMouse (1).pressed;
			clicked = true;



			if(currentClicked != null && currentClicked.CompareTag ("Robot")){
				selectedRobot = currentClicked;

				BehaviourTree tree = selectedRobot.GetComponent<BehaviourTree> ();
				if (tree != null&& tree.lastLoadedTree.Length > 0){
					Kontext.value = tree.lastLoadedTree;
				}
			}

			if (currentClicked != null && (currentClicked.transform.IsChildOf (transform) || currentClicked.CompareTag ("Robot")))
				NGUITools.SetActiveChildren (gameObject, true);
			else {
				Kontext.Close ();
				NGUITools.SetActiveChildren (gameObject, false);
			}
		}


		if (currentClicked!= null && clicked && currentClicked.CompareTag("Robot")) {
         	transform.localPosition = NGUIMath.ScreenToPixels(UICamera.GetMouse (1).pos,UICamera.currentCamera.transform);
			NGUITools.SetActiveChildren(gameObject,true);
			clicked = false;
		}


	
	}
Example #19
0
 private void CheckTerrainCollision(GameObject target)
 {
     // テラインに接触したら沈んだ音を再生
     if (target.CompareTag("Terrain"))
     {
         PlayAudioAtOnce();
     }
 }
Example #20
0
 private void CheckDamageCollision(GameObject target)
 {
     // 若干スピードを落とす微調整(あまりスピードがありすぎるとexplosionがきかない)
     if (target.CompareTag("Torpedo"))
     {
         controller.AddSpeed( -speedDown );
     }
 }
Example #21
0
 public void triggerExit( GameObject objectInTrigger )
 {
     if( objectInTrigger.CompareTag( "Player" ) )
     {
         foreach( GameObject douchbag in douchbags )
             douchbag.SendMessage( "DomainExited", objectInTrigger, SendMessageOptions.DontRequireReceiver );
     }
 }
Example #22
0
 private void CheckSonarPoint_Exit(GameObject target)
 {
     if (!target.CompareTag("Sonar")) return ;
     //        ColorFader fader = target.GetComponent<ColorFader>();
     //        if (fader) return fader.SonarInside();
     Debug.Log("CheckSonarPoint_TriggerExit");
     target.SendMessage("OnSonarOutside");
 }
 /// <summary>
 /// Determines whether this instance can pick up the specified object.
 /// </summary>
 /// <returns><c>true</c> if the ball can pick up this object; otherwise, <c>false</c>.</returns>
 /// <param name="other">The object to pick up.</param>
 bool CanStick(GameObject other)
 {
     bool stick = false;
     switch (stickyness)
     {
     case Stickyness.Weak:
         stick = other.CompareTag("Small");
         break;
     case Stickyness.Medium:
         stick = other.CompareTag("Medium");
         break;
     case Stickyness.Strong:
         stick = other.CompareTag("Large");
         break;
     }
     return stick;
 }
Example #24
0
    void CheckSonarCamera_Exit(GameObject target)
    {
        if (!sonarInside) return;
        if (!target.CompareTag("SonarCamera")) return;

        Debug.Log("CheckSonarCamera_Exit");
        OnSonarOutside();
    }
Example #25
0
 private void Hit(GameObject c)
 {
     if (c.CompareTag ("Player") && !destroyPlayer) {
         PlayerHit ();
     } else {
         Destroy(c.gameObject);
         GameobjectCounter.gameObjects--;
     }
 }
Example #26
0
 private void CheckSonarPoint_Enter(GameObject target)
 {
     if (!target.CompareTag("Sonar")) return;
     ColorFader fader = target.GetComponent<ColorFader>();
     if (fader==null) return;
     if (fader.SonarInside()) return;
     Debug.Log("CheckSonarPoint");
     target.BroadcastMessage("OnSonarInside");
 }
Example #27
0
 static void RenderLightGizmo(GameObject gameObject, GizmoType gizmoType)
 {
     if (gameObject.CompareTag("StationSpawn") && string.IsNullOrEmpty(AssetDatabase.GetAssetPath(gameObject))) {
         Gizmos.color = Color.yellow;
         var prefab = (GameObject)GameObject.FindObjectsOfTypeIncludingAssets(typeof(GameObject)).First(g => ((GameObject)g).name == "Work Station");
         var modelTransform = prefab.transform.FindChild("Cube");
         Gizmos.DrawCube(gameObject.transform.position, modelTransform.localScale);
     }
 }
 public void removeTarget(GameObject obj)
 {
     //Debug.Log("Hit");
     if(obj.CompareTag("PileOFish"))
     {
         targetMover.GetComponent<TargetMover>().PileOFishCounter -= 1;
     }
     targets.Remove(obj);
     Destroy(obj);
 }
Example #29
0
    /// <summary>
    /// Coloca la imagen en la posicion indicada.
    /// </summary>
    /// <param name="pGo">Objeto que contendra la imagen.</param>
    /// <param name="pSprite">Sprite.</param>
    /// <param name="pPos">P position.</param>
    public static void colocarImagen(GameObject pGo, Sprite pSprite, Vector2 pPos)
    {
        SpriteRenderer imagen = pGo.GetComponent<SpriteRenderer>();
        if (imagen == null){
            pGo.AddComponent(typeof(SpriteRenderer));
            imagen = pGo.GetComponent<SpriteRenderer>();
        }
        imagen.sprite = pSprite;
        //imagen.sortingLayerName = "Background";
        imagen.transform.position = Mazmorras.colocar16x16(pPos.x,pPos.y);

        if (pGo.CompareTag ("Wall") || pGo.CompareTag ("Rock") || pGo.CompareTag("Door")) {
                    pGo.AddComponent (typeof(BoxCollider2D));
                    imagen.sortingLayerName = "Walls";
        } else if (pGo.CompareTag ("Door")) {
                pGo.AddComponent (typeof(Door));
        }

        pGo.AddComponent (typeof(ColorChanger));
    }
 bool IsExplodable(GameObject obj)
 {
     if (Exploder.DontUseTag)
     {
         return obj.GetComponent<Explodable>() != null;
     }
     else
     {
         return obj.CompareTag(ExploderObject.Tag);
     }
 }