|
I have this script, and I want "tempbrick" to be parented to the object this raycast hits. How? I only understand that you have to instantiate, then parent the new object to the one I need. I just don't know how to declare tempbrick's transform as a variable.
(comments are locked)
|
|
There's something about what you're trying to do here makes me really want to see this work (I smell a good idea?). I'm going to take a shot at doing this from scratch: I don't even know if that will compile but it should work (it did in my mind at least) Oh dear lord it worked... You uh, I feel bad about abusing the system and squeezing this successful code out of you. I'm not sure how to go about this... Anyway, if I'm successful with this whole project, you might just see it come to fruition. I might even make a little inside reference to this whole incident. Thank you with the BREADTH OF A THOUSAND WORLDS.
Jul 21 '11 at 06:35 AM
Rsan
It's less of you abusing the system and more of you found a random guy online who had too much time on his hands and a disposition for helping people. But an up vote and a check would be nice though :P On topic: I think the problems in you script were that 1) You were using the 2) You were not using " 3) When you were calling Really that's it :) You're logic was OK, you were just fighting the compiler without knowing it.
Jul 21 '11 at 04:59 PM
SilverTabby
(comments are locked)
|
|
I was trying to be vague so that you would figure it out on your own, but obviously I'm being too vague. Here's a fish: "Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime." The teaching is in my comments ( well at least I tried to teach in the comments :\ ). I figured that. I'll try to do the rest on my own. Just one last question: does the order in which I declare variables and specify events count?
Jul 20 '11 at 05:07 AM
Rsan
a + b == b + a Generally, order does not mattter, as long as a variable exists when you are doing something to it. Though you should still be careful because the one time it does matter, it's easy to miss.
Jul 20 '11 at 05:21 AM
SilverTabby
Ok. And when you say "some code omitted", do you mean in the line itself, or the bits and pieces above and below that one line? As I have it now, it seems like it should work. Only it doesn't. I'm a bit stressed about this because this code is the absolute basis of this entire project. I can't really get started until this is complete.
Jul 20 '11 at 05:44 AM
Rsan
It's the bits and pieces above and below that one line. Not only that but those bits and pieces are the code you posted in the original question. I'm going to copy-paste some advice I gave in another question:
Jul 20 '11 at 06:05 AM
SilverTabby
This is probably is the last thing you want to hear(read?), but sometimes It's better to just open a blank file and try again. Retype the bits that worked and restart the bits that don't work. Less is more. I had a giant mess of code with classes inside of classes and more variables than you could count. It sort of worked. Then we destroyed a motor because of it. I opened a new file, redid everything, cut off 80% of the code, and it worked like a charm. Never had another problem with it. Less is more.
Jul 20 '11 at 06:18 AM
SilverTabby
(comments are locked)
|
http://unity3d.com/support/documentation/ScriptReference/Transform-parent.html http://unity3d.com/support/documentation/ScriptReference/RaycastHit-transform.html Hope this helped "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption." I put "tempbrick.transform.parent = hit.transform;" right after "Debug.Log(objectBounds);".
Jul 19 '11 at 11:42 PM
Rsan
If tempBrick is the top node in an instance, it will work fine. You definitely CAN make an instance the child of a transform in another prefab's instance. [Edited for clarity]
Jul 20 '11 at 12:13 AM
Rafes
Oh you need to instantiate the prefab first. The data corruption message means you are trying to edit the template (prefab) of an object instead of the instance of the object (The GameObject returned by Instantiate) Just replace tempbrick with Instantiate(tempbrick, location, Quarternion.Identity).transform.parent = //...
Jul 20 '11 at 12:15 AM
SilverTabby
Well, apparently here it isn't working. I'm considering it's because it's trying to somehow parent the object before it's even instantiated. I've seen other questions almost exactly like this, only they don't involve the clone limitation that's implemented here. Any thoughts? EDIT Oh, I'll try the above.
Jul 20 '11 at 12:17 AM
Rsan
Which "tempbrick" am I supposed to replace that with? And what do mean by "location"?
Jul 20 '11 at 01:30 AM
Rsan
(comments are locked)
|
