How to enable hidden objects using tags?

Hi everyone!

Im doing a car game, in the first moment you have a old car, but when you pass through an Item, the car change for one new model.

In my first try.
in the collinder object remove the old car and replace it for the new one, positioning in the same place, but lose the velocity and the connection with others scripts.

void OnTriggerEnter(Collider other)

{
	print("Upgread!!");
	car_2.transform.position = car_1.transform.position;
	car_2.transform.rotation = car_1.transform.rotation;
	car_2.active = true;
	ReSpeed();

}

in my second try
I put all the component fomr car 2 in the first car(old one) and asing a TAG for it.
old car have TAG CarOne
new car have TAG CarTwo
when the game start hide every object with CarTwo TAG, but when pass throw the item, I
can show again the objects.

function Update ()
{
CarTwo_array = GameObject.FindGameObjectsWithTag(“CarTwo”);
for(var go : GameObject in GameObject.FindGameObjectsWithTag(“CarTwo”))
{
go.active = false;
}
print(“Car Two Hide!!!”);
}

function Show()
{
for(var go : GameObject in GameObject.FindGameObjectsWithTag(“CarTwo”))
{
go.active = true;
}
print(“Car Two Show!!!”);

}

any idea??? thanks! and sorry my english if is a little Tarzan Style XD

So here is your script rehashed to make a bit more sense and work using triggers.
I have not uses Tags as your question denotes as this, I at least I think, is a faster method to resolve your problem at hand.

It takes advantage of the parent child control hierarchy now, which means by adding the below script to an empty parent GameObject you can can then child your cars to it, zero their coords to the newly created empty GameObject so they are exactly positioned the same and add them in the empty gameobjects inspector where the below script should be.

1:Empty GameObject
2:Add Collider to newly created Empty GameObject, tick isTrigger.
3:Add rigidbody component and tick “isKinematic”, untick “useGravity”.
4:Chuck Both Cars in Empty GameObject and align them at 0 with empty gameobject.
5: add car 1 to car 1 slot of empty game object with below script attached to it.
6: do the same for car2.
Remove all other colliders/or atl east disable the ones you were using before as the collision is triggered through the parent you just made and set to “isTrigger”.

Code below bud.
take care Gruffy.

using UnityEngine;
using System.Collections;
/// <summary>
/// Gruffy 2013:)
/// Make an empty gameobject where you already have your cars placed in scene and call it "Parent" for posterity.
/// Add a box/sphere collider and set it to be a trigger (isTrigger)
/// Add a rigidbody component and tick  "isKinematic", untick use gravity.
/// Add this script to your newly created empty gameobject.
/// Add you car1 and car2 game objects into the newly created empty gameobject and zero them out position wise.
/// make sure your collider where your change shoudl occur is also set to isTrigger..
/// 
/// 
/// </summary>
public class SwapEmOver : MonoBehaviour 
{
	public GameObject car1; //both car1 and car2 are now children on the GameObject you have this script attached to
	public GameObject car2;
	// Use this for initialization
	void Start () 
	{
		if(car1 && car2 != null)
		{
		car1.SetActive(true);
		car2.transform.renderer.enabled = false;
		car2.SetActive(false);
		car1.transform.renderer.enabled = true;

		}
	}
	void OnTriggerEnter(Collider other)
	{
		print("Upgread!!");
		car2.transform.position = car1.transform.position;
		car2.transform.rotation = car1.transform.rotation;
		car2.SetActive(true);
		//ReSpeed(); dont know what this is

	}

	// Update is called once per frame
	void Update () 
	{
		if(car2.activeSelf)//car 2 is now active from trigger event
		{
            //set car 1 to disappear
			car1.transform.renderer.enabled = false; //not really necesasary as we are going to destroy it...
			car1.SetActive(false); //...here
            //show car 2 in case that is set to false for any reason
			car2.transform.renderer.enabled = true;
		}
        //this was a test when i wrote this script in Unity a minute ago
        //transform.Translate(Vector3.back * Time.deltaTime);
	}
}

EDIT: here is a [24386-proofofconcept_swapoverscript.zip|24386] package that shows you the proof of concept, set up and functionality that was made using the above script.
take care dude, hope that helps you somewhat.
Edit: added pure trigger functionality, removing need for Update, code is also below to show the differences between the two solutions.

[24396-proofofconcept_swapoverscript2.zip|24396]

Alternative Code:

using UnityEngine;
using System.Collections;
/// <summary>
/// Gruffy 2013:)
/// Make an empty gameobject where you already have your cars placed in scene and call it "Parent" for posterity.
/// Add a box/sphere collider and set it to be a trigger (isTrigger)
/// Add a rigidbody component and tick  "isKinematic", untick use gravity.
/// Add this script to your newly created empty gameobject.
/// Add you car1 and car2 game objects into the newly created empty gameobject and zero them out position wise.
/// make sure your collider where your change shoudl occur is also set to isTrigger..
/// 
/// 
/// </summary>
public class SwapEmOver : MonoBehaviour 
{
	public GameObject car1; //both car1 and car2 are now children on the GameObject you have this script attached to
	public GameObject car2;
	// Use this for initialization
	void Start () 
	{
		if(car1 && car2 != null)
		{
		    car1.SetActive(true);
		    car2.SetActive(false);
		}
	}
	void OnTriggerEnter(Collider other)
	{
        car1.SetActive(false);
        car2.SetActive(true);
    }	
			

	void OnTriggerExit()
    {
        car2.SetActive(false);
        car1.SetActive(true);
    }
}

Gruffy :slight_smile: