- Home /
Duplicate Question
Duplication Problem. Please help.
Hello. I am fairly new to both Game Creation and Scripting. I had created a script that duplicated my set object. I also had another script that destroys the object when the player collides with the object. All goes well until the duplication part. When the object becomes duplicated it changes its name from "Apples" to "Apples(clone)" When it adds the "(clone) to the end it doesn't allow my destroy on collision script to work since the name isn't "Apples" This is the script using UnityEngine; using System.Collections;
public class DestroyApples : MonoBehaviour {
void OnCollisionEnter2D (Collision2D col)
{
//Check collision name
Debug.Log("collision name = " + col.gameObject.name);
if(col.gameObject.name == "Apples")
{
Destroy(col.gameObject);
}
}
}
Is there a way it can be duplicated without the "(clone)" or a way that it allows the script to detect the object.
Also here is my script for the duplication part.
#pragma strict
var theObject:GameObject;
var maxPosY:float = 25.0;
var minPosY:float = 25.0;
var minPosX:float = -2.55;
var maxPosX:float = 2.44;
var max = 22;
function Start(){
StartCoroutine(spawn());
}
function spawn() : IEnumerator {
for (var i = 0; i < max; i++) {
yield WaitForSeconds(5.0);
var theNewPos= new Vector3 (Random.Range(minPosX,maxPosX),Random.Range(minPosY,maxPosY));
var go : GameObject = Instantiate(theObject);
go.transform.position = theNewPos;
}
}
Sorry if my writing is in poor condition. I am quite tired. If any questions pop up, please ask.
All help is very much appreciated. Thank you.
Answer by hexagonius · Feb 28, 2015 at 09:25 PM
After instantiating set go.name = "Apples";
Thank you so much! This has removed all the stress I had about that one problem. Again I say, thank you.
@Hexagonius, this is a duplicate question.
Add your answer to the other QA thread.
@SUPPEAR Please go through your previous questions and conclude them. You have many unfinished questions.
Follow this Question
Related Questions
Expand object on touch? 1 Answer
Transform.LocalScale Script Problem. Please help. 2 Answers
Expand Object On Touch? Someone please help me 1 Answer
Collision On Specific Object= Destroy not working. 2 Answers
Scaling Script? 1 Answer