- Home /
Question by
Urbanite · Jul 02, 2013 at 11:55 AM ·
javascripttriggersword
enable components from multiple objects
im working on a medieval fantasy game. there is a part where you find a sword and pick it up, you press "e" when you are close to it, then it enables a bunch of components to make it seem like you just picked up the sword (even though you already had it, but the mesh renderer and etc where disabled), my script is giving me a massive headache it would be nice if i could get some help with it.
here's the script
var righthand : GameObject;
var swordfix1 : GameObject;
var skinnedmeshrenderer : GameObject;
private var sworddestroyed = false;
function Start() {
swordfix1 = GameObject.Find ("swordfix1");
righthand = GameObject.Find ("Right Hand");
skinnedmeshrenderer = GameObject.Find ("skinned mesh renderer");
}
function Update()
{
if (Input.GetKeyDown("e")){
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 4)){
// what did the raycast hit ?
Debug.Log( "ray hit (name): " + hit.collider.gameObject.name);
Debug.Log( "ray hit (tag): " + hit.collider.gameObject.tag );
if ( hit.collider.gameObject.name == "sword01" )
{
var sworddestroyed = true;
Destroy(hit.collider.gameObject);
}
}
}
GameObject.Find(righthand);
GameObject.GetComponent(Animation).enabled = true;
GameObject.GetComponent(Weapon Sway).enabled = true;
GameObject.GetComponent(Sword anim).enabled = true;
GameObject.GetComponent(Audio Source).enabled = true;
GameObject.Find(swordfix1);
GameObject.GetComponent(Mesh Renderer).enabled = true;
GameObject.Find(skinnedmeshrenderer);
GameObject.GetComponent(Skinned Mesh Renderer).enabled = true;
}
Comment