How to "talk" to the instantiated objects?, C#

Hi

I have problem,
I want to create an object, and then change it’s tag
Part of my script is this:

...
if (map [ (K - 1) * 32 + (L-1)] >= 70  map [ (K - 1) * 32 + (L-1)] < 80)
{
Instantiate ( Waypoint,  new Vector3(310 - (K-1)*10, 0.1f, (L-1)*10), Quaternion.identity);
[COLOR="red"]//change tag[/COLOR]
}
...

What do I have to write instead of “change tag” in the script to change INSTANTIATED OBJECT’S TAG

first of all What is the name of new instantiated object?
I’ve been searching in help it says that Instantiate returns rigidbody, object, missle,… but I need to get into that object’s Tag or Transform (I need GameObject)
I’ve tryed to get that rigidbody

...
if (map [ (K - 1) * 32 + (L-1)] >= 70  map [ (K - 1) * 32 + (L-1)] < 80)
{
Rigidbody InstObj;
InstObj = Instantiate ( Waypoint,  new Vector3(310 - (K-1)*10, 0.1f, (L-1)*10), Quaternion.identity);
[COLOR="red"]//change tag[/COLOR]
}
...

but how to change tag if I have rigidbody :confused:

rigidbodies don’t have tabs, so it would be InstObj.gameobject.tag

Rigidbody is a Component.

Instantiate is for GameObjects and Prefabs(could have Rigidbody preattached)

GameObject InstObj;
InstObj = Instantiate(…
InstObj.tag = …
InstObj.name = …

ty
btw that means that RIGIDBODY owns (is parent of) gameObject?
I though that gameObject owns rigidbodies :confused:

I have seen in help manual that they are instantiating Rigidbody, but now I’ve noticed that I’m instantiating GameObject prefab, so my variable InstObj can’t be Rigidbody (it says that it should be Object)

Error:
Assets/Scripts/Game/TerrainA.cs(45,41): error CS0266: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.Rigidbody’. An explicit conversion exists (are you missing a cast?)

so I’ve tried to put Object:

...
public [COLOR="purple"]GameObject[/COLOR] [COLOR="deepskyblue"]Waypoint[/COLOR];
...
if (map [ (K - 1) * 32 + (L-1)] >= 70  map [ (K - 1) * 32 + (L-1)] < 80)
{
[COLOR="blue"]Object [/COLOR]InstObj;
InstObj = Instantiate ( [COLOR="deepskyblue"]Waypoint[/COLOR],  new Vector3(310 - (K-1)*10, 0.1f, (L-1)*10), Quaternion.identity);
//change tag
}
...

Now it haven’t got Errors BUT I can’t reach transform or tag with
InstObj.gameObject.tag
InstObj.gameObject.transform.position.x

when I put GameObject;
Error:
Assets/Scripts/Game/TerrainA.cs(45,41): error CS0266: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.GameObject’. An explicit conversion exists (are you missing a cast?)

I have tried to set a GameObject variable first but it didn’t worked.

GameObject InstObj = Instantiate (GameObject)( Waypoint, new Vector3(310 - (K-1)*10, 0.1f, (L-1)*10), Quaternion.identity);

GameObject InstObj = Instantiate (GameObject)( Waypoint…

not working :confused:

Errors:
Assets/Scripts/Game/TerrainA.cs(45,74): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

Assets/Scripts/Game/TerrainA.cs(45,62): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object)’ has some invalid arguments

Assets/Scripts/Game/TerrainA.cs(45,62): error CS1503: Argument #1' cannot convert object’ expression to type `UnityEngine.Object’

I’ve told you only Object works:
Object InstObj = Instantiate ( Waypoint…

but how to get tag and transform? :/.

heres a script i use that works it might help. you can yous more then just object if you cast right

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Rigidbody))]
public class InstantiateExplosion : MonoBehaviour
{
public GameObject explosion;
private GameObject tempExplosion;
public float timeOut = 5.0f;

void OnCollisionEnter(Collision collision)
{
ContactPoint contact = collision.contacts[0];
//Quaternion rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);

if (Network.isClient || Network.isServer)
{
tempExplosion = (GameObject)Network.Instantiate(explosion, contact.point, Quaternion.identity, 0);
Kill();
return;
}
else
{
tempExplosion = (GameObject)Instantiate(explosion, contact.point, Quaternion.identity);
Kill();

return;
}
}

void Kill()
{
transform.DetachChildren();
Destroy(gameObject);
}
}

...
public Transform Waypoint;
...
if (map [ (K - 1) * 32 + (L-1)] >= 70  map [ (K - 1) * 32 + (L-1)] < 80)
{
Waypoint = (Transform) Instantiate ( Waypoint,  new Vector3(310 - (K-1)*10, 0.1f, (L-1)*10), Quaternion.identity);
Waypoint.gameObject.tag = "myTag";

untested

NICE!
handsomePATT I have checked out your script and remade mine, now it works! :smile:

answer:
GameObject InstObj = (GameObject)Instantiate( Waypoint…

now I can do
InstObj.tag = …

thank you very much all of you,
and handsome ty for making your 100th comment in my thread :stuck_out_tongue:

haha glad i could help