- Home /
Make Extensions return a value
Yeah, so i'm trying to make an Extension for myself. But i can't figure out a way to actually make my extension return a value. here is what i have so far:
public static class Extension_Damage
{
public static void doDamage( this Transform target, float damage )
{
//return damage * 2;
}
}
i tried IENumerator, removing the static and some more. Please help me
Answer by InfiniBuzz · Jul 11, 2013 at 04:42 PM
Hi
you have to specify the return type of the function. Its currently void
- change it
public static class Extension_Damage
{
public static float doDamage( this Transform target, float damage )
{
return damage * 2.0f;
}
}
syntax is like:
<visibility> <return type> <name>(<parameters>)
{
<function code>
}
However you should think about your function :) it makes no use of the first parameter. But I think you are going to extend this ;)
hope it helps
yeah, I just got into extensions today, but anyways you helped me to fix my problem for now. thx :)
Absolutely correct. Extensions can be really useful, but this one makes no sense at all ;) Even if it uses the Transform in some way, you should think about if it actually makes sense to all Transforms. Or atleast you need it very often.
i actually had some script on there, but i took it out, just to simplify it for my question ;)
Your answer
Follow this Question
Related Questions
World Builder from Unity Asset Store 3 Answers
What is the meaning of Generators cannot return values? 1 Answer
Member variables returning to 0 0 Answers
Time.deltatime is returning 0? 1 Answer