hi to all
I want to instantiate an object(RigidBody) when user press a GUIButton(attack). The GUIButton with instantiating script is attach to a empty game Object and the empty game Object is a child of my character. so I want to instantiate the rigidbody from my character controller script.
so what i think is i need to use my empty game Object to instantiate the rigid body. so to do this i need to use GetComponent(empty game object); in character controller script. But its a big confusion to me. How to do this ?
here is the code of my empty game object(weaponlauncher):
var cube : Rigidbody;
var Player : GameObject;
var speed =20;
function Update()
{
var instantiatedProjectile : Rigidbody = Instantiate(cube, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(speed,0,0));
Physics.IgnoreCollision( instantiatedProjectile. collider,transform.root.collider );
}
here is my character controller script only the GUI function lines :
function OnGUI(){
if(GUI.Button(Rect(300,300,80,20),"Attack"))
{
ins = GameObject.Find("weaponlauncher");
insscript=(weaponlauncher)ins.GetComponent(typeof(weaponlauncher));
insscript.Instantiate(cube, transform.position, transform.rotation );
_characterState = CharacterState.Attacking;
}
}
i know what i have done is all silly. but i have told that i am confused so help me to understand this