- Home /
Pass Enum To Function Parameter
Hello,
On one script I have a enum variable, and I want to send the enum in a SendMessage as a parameter to another script, like so:
Weapon Object
// ----- Weapon Pickup ----- \\
enum selectWeapon {Gun, LargeGun}
var typeOfPickup : selectWeapon;
function OnCollisionEnter(hit : Collision){
hit.collider.SendMessageUpwards("changeWeapon", typeOfPickup, SendMessageOptions.DontRequireReceiver);
}
And on my player
// ----- Player / Receiver ----- \\
function changeWeapon(weapon : ???) {
if(currentWeapon == weapon.Gun){
//do something
}
}
Any ideas how I can do this?
Thanks
weapon:selectWeapon tht doesnt work?? in tht case u gotta use int =/
Answer by flamy · May 21, 2012 at 08:57 PM
I tried to make a parameter of type _try(enum) and also int both worked for me. the below is the code. casting it to int would definitely work. Also i remember enum not working properly for if loops on another sciprts (in unity script), so used to follow casting to int method.
public class enumChecker : MonoBehaviour {
_try obj=_try.blah;
// Use this for initialization
void Start () {
haha ((int)obj);
}
// Update is called once per frame
void Update () {
}
void haha(int temp)
{
print((_try)temp);
}
}
public enum _try
{
lol,
meh,
blah,
rofl,
lmao
}
Answer by rutter · May 21, 2012 at 08:45 PM
You should be able to use selectWeapon
as the type, as far as I can see. Is that not working?
Your answer
Follow this Question
Related Questions
How to Send Message to other GameObject 3 Answers
BroadcastMessage 1 Answer
Flame Thrower - Particle Collision Help 1 Answer
How do i Specify a Receiver for a Send Message Function? 2 Answers
Player Character Health 2 Answers