Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by kici · Dec 28, 2010 at 07:13 PM · instantiateprefabclone

Clone Prefab Duplicate Problem

Alright well, I'm making an asteroid field with Instantiate(asteroid, position, Quaternion.identity);

where asteroid is a gameobject - prefab,

and now by doing that i make about 100 clones give or take, and on the prefab i have a script that has a raycast, and a random given number from 20 to a 100,

now I want each asteroid's script to be valued as individual instead if i select one asteroid all clones get selected, and if i want to destroy an asteroid after some period of time all clones of the same kind gets destroyed,,

anyone know how to help me so the script/clones are valuead as individual gameobjects or whatever,,, show examples if you can please and thanks.

Here's the code:

var asteroid : GameObject; var asteroid2 : GameObject; var asteroid3 : GameObject; var asteroid4 : GameObject;

var times = 0; var go : boolean = true; function Update () {

if(go) {
times++;
var position = Vector3(Random.Range(-2000, 2000), 0, Random.Range(-2000, 2000));
var position2 = Vector3(Random.Range(-2000, 2000), 0, Random.Range(-2000, 4000));
var position3 = Vector3(Random.Range(-2000, 2000), 0, Random.Range(-2000, 4000));
var position4 = Vector3(Random.Range(-2000, 2000), 0, Random.Range(-2000, 4000));
Instantiate(asteroid, position, Quaternion.identity);
Instantiate(asteroid2, position2, Quaternion.identity);
Instantiate(asteroid3, position3, Quaternion.identity);
Instantiate(asteroid4, position4, Quaternion.identity);
if(times >= 55) { go = false; 
}
}

}

THE ASTEROIDS SCRIPT:

var minerals = 0; var mayI : boolean = true;

function Update () { if(mayI) { minerals = Random.Range(30, 100); mayI = false; Debug.Log(minerals); }

if (Input.GetButtonDown ("Fire1")) { var hit : RaycastHit; if(Physics.Raycast(transform.position, transform.forward, hit)) { hit.transform.SendMessage("HitByRaycast",gameObject, SendMessageOptions.DontRequireReceiver); }

}

} // int = parseInt(variablename);
// int myBlubb = myFloatBlubb as int; //int myBlubb = (int) myFloatBlubb;

function HitByRaycast(source : GameObject) { Debug.Log("i've been hit"); Debug.Log(minerals); // Debug.Log(minerals); }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ejlersen · Dec 28, 2010 at 07:47 PM 0
Share

Could you show us the part, that selects an asteroid?

avatar image kici · Dec 28, 2010 at 10:06 PM 0
Share

ook i added that in there

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by s4vi0r · Dec 29, 2010 at 06:12 PM

When you instantiate a prefab the script attached to each one should be unique to that object. As far as you problem accessing the prefabs... It sounds like a naming problem. When you instantiate something just change its name to something unique..You could even build an array if necessary. Try something like this:

var asteroids : array;

...... asteroid = new array(); for(i = 0; i < 20) {

 var newWorldObject = Instantiate(asteroid, Vector(0,0,0), Quaternion.identity);

 //assigns names "asteroid0 - asteroid19" and adds them to array.
 newWorldObject.name = ("asteroid" + i);
 asteroids.Add(newWorldObject);

}

Hope this helps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to instantiate from prefab, not from instance? 3 Answers

Destroy 1 prefab object and changing the color/image 1 Answer

(Clone) from Instantiated Prefabs over Network 1 Answer

Assign an instantiated GameObject? 1 Answer

Instantiate Clones Itself - Rather than Prefab 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges