Hi all
Im sure this has been asked before but Im upgrading from 5.0 to 5.5 and got this error upon loading in the editor.
its line 47
error CS0030: Cannot convert type UnityEngine.Object[ ]' to
System.Collections.Generic.IEnumerable’
Any suggestion would be helpful, the original designer of the code isnt at the studio anymore so Im flying blind but hopefully there is a simple upgrade fix to this error.
Thanks in advance.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using UnityEngine;
using Object = UnityEngine.Object;
public static class ComponentExtensions
{
public static T Instantiate<T>(this T obj) where T:Component
{
return (T)Object.Instantiate(obj);
}
public static T InstantiateToParent<T>(this T obj, Transform parent) where T : Component
{
var ret = (T)Object.Instantiate(obj);
ret.transform.parent = parent;
return ret;
}
public static T InstantiateToParentLocal<T>(this T obj, Transform parent) where T : Component
{
var ret = (T)Object.Instantiate(obj);
var pos = ret.transform.localPosition;
var rot = ret.transform.localRotation;
var scale = ret.transform.localScale;
ret.transform.parent = parent;
ret.transform.localPosition = pos;
ret.transform.localRotation = rot;
ret.transform.localScale = scale;
return ret;
}
public static T Find<T>(this Object obj) where T : Object
{
return (T)Object.FindObjectOfType(typeof(T));
}
public static IEnumerable<T> FindMany<T>(this Object obj) where T : Object
{
return (IEnumerable<T>) Object.FindObjectsOfType(typeof (T));
}
public static void Invoke(this MonoBehaviour obj, Action action, float inSeconds, Func<bool> predicate = null)
{
if (obj is HKBehaviour)
obj.StartCoroutine(InvokeInSecondsHandlePause(obj as HKBehaviour, action, inSeconds, predicate));
else
obj.StartCoroutine(InvokeInSeconds(action, inSeconds, predicate));
}
static IEnumerator InvokeInSeconds(Action action, float seconds, Func<bool> predicate)
{
yield return new WaitForSeconds(seconds);
if (predicate == null || predicate())
action();
}
static IEnumerator InvokeInSecondsHandlePause(HKBehaviour behaviour, Action action, float seconds, Func<bool> predicate)
{
yield return new WaitForSeconds(seconds);
while (behaviour.IsPaused)
{
yield return null;
}
if (predicate == null || predicate())
action();
}
}