- Home /
how to paint gameobjects on other gameobjects
hi there!
is there a known way how to paint gameobjects on other gameobjects or growing some prefabs along a path or something like that?
thanx!
edit: what i had in mind was a little tool to paint on the surface of an object and along this path there would be created the copies of an prefab in predefined distances or "densities"... I will have some additional websearch to find some words to be more clear...
The instantiate function might be what you are looking for. Could you elaborate on what you want to do exactly?
oh, thats too basic, but thak you. :-) no - sorry if I was too unspecific. I want to "paint" prefabs on gameobjects just like you can "paint" trees on landscapes, if you know what I mean...
Saying pretty much the exact same thing again doesn't really make the question more specific or clarify your meaning.
Answer by skovacs1 · Nov 08, 2010 at 09:43 PM
If I get your meaning, you want to instantiate one or more GameObjects along the surface of another GameObject, is that correct?
To do this, you would raycast and instantiate with the up vector being the normal of the surface that was hit, determining the rest of the new orientation some other way. Positioning is trickier because the object you are instantiating might have the pivot at the center (as opposed to the bottom), so you would have to calculate the offset to the bottom of the GameObject and instantiate at the hit.position + newOrientation * offset.
yes, you understood me right. thanx for the tip! this would be one way. but what i had in $$anonymous$$d was a little easier to use, like a tool to paint on the surface of an object and along this path there would be created the prefabs in predefined distances or "densities"...
That's the same, but you would add some sort of ti$$anonymous$$g mechanism to tell how long/hard they hold in a position and you would perform your instantiation based on that. If you wanted the path first so that it could be changed or something, on raycast, ins$$anonymous$$d of instantiating the objects explicitly, you'd mark the points of the path on the surface (either by editing a texture or placing gameObjects that you then store in some sort of public container, etc.) and then when you want to instantiate, you'd read in the texture/gameObjects and instantiate based on that.
Answer by headkitgames · Nov 19, 2010 at 11:04 AM
so with something like that i could start
function Update() { if (Input.GetButtonDown("Fire1")) { var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 100))
{
var otherObj : GameObject = hit.collider.gameObject;
Debug.Log("Hit: " + otherObj.name);
if(otherObj.name == "nameOfObjectToPaintOn")
{
var newPos : Vector3 = new Vector3(hit.point.x, 0.8, hit.point.z );
var newObject : GameObject = Instantiate(thePaintPrefab, newPos, Quaternion.identity) as GameObject;
newObject.name = "newBulb_" + ++cnt;
allNewBulbs.Add(newObject); // to store the new positions
}
}
}
}