- Home /
Instantiating on passed parameters?
Basically, I'm trying to instantiate a breaching charge on a wall. It's easy enough to instantiate on a fixed position, but I'm looking to pass two parameters into the PlantCharge() function that the contains my instantiation of the charge. I want to pass the two parameters, which will be the rotation and position of wall, but it seems that I'm stuck with Vector3 for the position and Quaternions for the rotation.
I was hoping to have the player plant a charge on a wall, and then have the walls position and rotation be the position and rotation for the charge.
Is it at all possible to take those two variables as parameters? I'm writing in C#.
Seeing your code would be really helpful. Is the issue getting the position and rotation of the wall? How is the player detecting the wall?
public class TileFunctions : Inventory {
void PlantCharge(Transform tilePos, Transform tileRot)
{
GameObject breachingCharge = GameObject.Find ("BreachingCharge");
Instantiate (breachingCharge, tilePos, tileRot);
}
$$anonymous$$eep in $$anonymous$$d, the game is 2D. I don't need to use raycasts, or any fancy 3D functions, this is an aerial view, tile based game.
Answer by Slev · Sep 23, 2014 at 01:04 PM
It sounds like you need to redefine how your code is structured. In pseudo code:
Raycast verify we are allowed to plant.
If yes, use HitInfo to get rotation and position of wall.
Instantiate the object using the wall's position and rotation. (Quaternion.Euler)
Initialize anything else.
You should already be verifying the wall so this shouldn't add much more to your code.