i would like to make a script that when i run into a certain object make weapon prefab(in this case bullet prefab) changes. (ex. i start with my fireball prefab, i run into a certain cube, my fireball prefab changes into my iceball prefab.) I know it has to deal with the function OnTriggerEnter(hit : Collider) and possibly tags, but i don't know the script to change a prefab.
Assuming you instantiate these prefabs when you fire a bullet, the general idea would be to assign both normal bullet prefab and ice prefab in the Inspector, have the trigger script set some global variable denoting the current bullet type, and then instantiate the bullet depending on the type.
public var normalBulletPrefab:GameObject;
public var iceBulletPrefab:GameObject;
public var isIceBullet:bool; // you probably want to use an enum here, to have different kinds of bullets
function FireBullet(){
if(isIceBullet)
Instantiate(iceBulletPrefab);
else
Instantiate(normalBulletPrefab);
}
and in your Trigger script you would set the isIceBullet variable of this script.
I would think you would just create a global to hold the current weapon prefab and then change that when you hit the trigger...
so your script that throws fireball or iceballs would contain something like this...
var weaponPrefab : GameObject; // drag and drop default prefab in explorer
function OnTriggerEnter( hit : Collider )
{
var newPrefab : WeaponPrefabSpec = hit.gameObject.GetComponent( "WeaponPrefabSpec" );
if( newPrefab && newPrefab.weaponType )
weaponPrefab = newPrefab.weaponType;
}
then the "box" you collide with that determines what type of prefab to use would have a script titled "WeaponPrefabSpec" that just has a variable value in it...
var weaponType : GameObject;
Now you can attach the script to the cube and assign the prefab you want used when you collide with it to the "weaponType" variable. When the player controller collides with the cube, if the cube has the script and a value assigned to the variable, the player will change the prefab they're using.