It provides the modes nearest, furthest, weakest, strongest, slowest and fastest. For example in the old towerdefence game onslaught you can change the targetting mode of every turret with the key “T”. Since you rotate slowly you might never actually point at any of the enemies. Since the distance to the enemies can change from frame to frame your object might rapidly switch between two or more enemies. The second mode has a slight issue when you rotate slowly towards your target. Either lock-on target until it’s dead or out of range or always pick the closest one. However there are generally two targetting modes. ![]() My guess is you want to rotated towards the closest enemy in range. Also do not put too much different functionality into one method. In this case it rotates slowly towards that enemy and returns true, otherwise it returns false. ![]() All it does is checking if the first enemy returned by FindGameObjectsWithTag is within the fireing range. You called it “ShootEnemy” but it doesn’t seem to shoot anything. Inside your loop you always have a return statement. Your loop does never ever get to the second element in the array, no matter what happens. Your overall logic seems to be backwards and pretty messed up. So if enemy is null you won’t get past this point. However if that’s the case you get a null reference exception at line 10 since you try to access the transform component of enemy. Because if target is null at that point it means your “enemy” variable is null. inside your foreach loop you have this if statement: if (target = null) However your method has some logical flaws. the easiest solution is to add a return statement at the end of the method. So like others have already mentioned you just have to follow all your possible cases and make sure there is always a return statement when the method finishes. Keep in mind that the compiler is pretty “dumb” because even in situations where it’s seems obvious to you that you will reach a return statement, from the compilers view that’s not guaranteed. So your execution just skips the foreach loop and you reach the end of the method without returning anything. This will completely skip your foreach loop. ![]() ![]() That means the method returns an empty array. You use the method “FindGameObjectsWithTag”. However in both cases there is the possibility that the loop doesn’t run at all. A “for” or “foreach” loop has a condition when to terminate. A method that has a return value must always return a value, not matter which code path you might go. Any kind of branching will create two possible ways how the execution might continue. A code path is the path of execution that the processor can go through your method until it finishes / leaves the method. However first address your apparent error. For other uses, see Cross product (disambiguation).Your code has several issues. This article is about the cross product of two vectors in three-dimensional Euclidean space.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |