itween add null checker

how can i add null to this script to see if a object has been destroyed?

public static void Stop(GameObject target, string type)
	{ Component[] tweens = target.GetComponents(typeof(iTween));
	foreach (iTween item in tweens){ string targetType = item.type+item.method;
	targetType=targetType.Substring(0,type.Length);
	if(targetType.ToLower() == type.ToLower()){ item.Dispose(); } } }

oiiiii format your code please you have 1010101 on the top

1 Answer

1

BTW your code was very bad written so I had to re edit it to even see what’s going on

next time I’ll leave the down vote

I removed it as you did help me help your self

public static void Stop(GameObject target, string type){
	if (target == null){
		return;
	}
	Component[] tweens = target.GetComponents(typeof(iTween));
	foreach (iTween item in tweens){
		string targetType = item.type+item.method;
		targetType=targetType.Substring(0,type.Length);
		if(targetType.ToLower() == type.ToLower()){
			item.Dispose();
		}
	}
}

all you need to enter is

after the start of your function

		if (target == null){
			return;
		}

else you would wrap whole your inside of function in to:

		if (target != null){
			// your code you need
		}

Thank you so much i have been working on this for days, you just saved my life:)

ok i tried the code and it stopped giving me the error, but it is messing up my itween functions on some objects that do not get deleted.

I solved this error and everything is working great.:)