- Home /
Generic methods in UnityScript
is there a feature in UnityScript that able us to create generic methods?
something like:
function DoSomething<T>() : T {
return GameObject.Instantiate<T>(...);
}
Answer by Bunny83 · Feb 20, 2012 at 02:15 AM
I don't think that's possible in UnityScript. AFAIK this example wouldn't even work in C# since Instatiate's generic parameter has a constraint to UnityEngine.Object so you can't use an unconstrainted parameter. Maybe there's some magic secret syntax which allows you to sepecify a constraint in UnityScript, but i guess it's another thing which isn't possible in UnityScript like: inheriting from additional interfaces, declaring interfaces, declaring indexer, ...
Answer by zpinner · Feb 20, 2012 at 01:29 PM
maybe the example with Instantiate wasn't good, I just wanted to ilustrate a generic use. is there any other possible way to work with generics in unityscript?
Your answer
Follow this Question
Related Questions
Unity Steer, C# to UnityScript 1 Answer
Adding an offset to an instantiated objects rotation 0 Answers
Best Performance: Tag or GetComponent + Rendering/Diactivating 1 Answer
Need to walk idly around unless ball is around 1 Answer
null reference exception problem with generic lists in unityscript (i think...) 1 Answer