Collision (and other shenanigans)

I’m still a beginner at scripting (C#) and I was having trouble locating some specifics on collision. Currently, I have:

void OnCollisionEnter()
{
Destroy(gameObject);
//Transform enemy;
//enemy = Instantiate
}

But this is if it collides with anything. How can I call out specific items to collide with? Is there a central collision… tutorial database somewhere? : P

I found those same areas, but I’m a little unclear as to how they connect. What (I think) I’d like to do is allow a collision detection determine an effect based on what it encounters. For example:

if(collide with x || y)
{
a happens
}

if(collide with z)
{
b happens
}

Something of that nature.

void OnCollisionEnter(Collision collision){
	if(collision.gameObject.CompareTag("TagImLookingFor"){
    		//do something
	}
}

Thanks for the help legend.

Can someone explain how the range of numbers work here? It seems like I can choose a range for x and z but y is a single number?

Vector3 position = new Vector3(Random.Range(0, 0), 0, Random.Range(0, 0));
Instantiate(redenemy, position, Quaternion.identity);

The random range documentation contains an example that shows exactly that

In that example the Y component is set at zero, replace the zero with another random range call!

Oh, I get it. Each integer is replaced with the entire Random.Range call, including the right?

Edit: Here I’m trying to get a Random.Range for X, with a specific Z and Y coordinate. But it doesn’t seem to be working. Right when I thought I understood the Random.Range…

	void SpawnRedEnemy()
	{
        float addPos = (Random.Range(-250f, 250f), 0, 110);
        Vector3 spawnPos = transform.position + new Vector3(addPos,0,0);
        Instantiate(redEnemy, spawnPos, Quaternion.identity);
	}

This was cut from an example project involving falling eggs and catching them into a bucket. Also, what do those "f"s mean?

Edit 2: Ah, I think I’ve figure it out.

void SpawnRedEnemy()
	{
        float addXPos = Random.Range(-250, 250);
        Vector3 spawnPos = transform.position + new Vector3(addXPos,-10,105);
	Instantiate(redEnemy, spawnPos, Quaternion.identity);
	}

My question is, is this “float addXpos” needed? I have this attached to my camera and my enemies were Instantiated based off that. Should I be forcing a world coordinate or creating an empty object where I want the pivot points for enemy spawns?

Is there a multiplier you can add to Instantiate calls? For example:

Public float enemyMultiplier;

Instantiate(myPrefab) * enemyMultiplier;

Or something of that nature?

Edit : I was fixing something you had already fixed in your last post. What you are doing there seems fine to me. Thats the way to do it.

Oh, so Instantiating a prefab works that way? I can just multiply it by a number and it will do it 5 times?

Nope, you will have to do 5 instantiations. Aside from that there are no numbers telling it what the offset values are if you did that.

You can define a new function that will instantiate multiple times. You would just need to feed it an object, initial position, initial rotation, local offset and local rotational offset. create the first object, then do a loop for the rest, and every object you create is trasnformed by the object preceding it

If you created a hundred objects with a slight rotation and offset, it would make a cork screw.

OK, thanks. Let me chew on that for a bit.

Should I be putting collision detection in the “void Update” or in a “void OnCollisionEnter(Collision collision)” piece assuming I want to continually detect if a player is colliding with enemies, enemies are colliding with players, etc… what’s the difference between these two items?

Edit: Additionally, is it safe to say I should typically use “OnTriggerEnter/Exit/Stay” to detect collision when I’m working with a game that does not have physics?