|
Hi everyone, I am trying to use FindWithTag to search for all of the enemies on the screen with tag "enemy". The script works fine and it finds all of them, however if all enemies are destroyed, the script sends me an error message saying "NullReference...", and I have no idea how to fix it :(. I did try using GameObject instead of Transform and it works fine, however later in the script I am trying to use the LookAt which needs "Transform" and gives me error. It doesn't matter which way I go, it will give me an error, which I cant fix myself. Do you have any idea how to fix it? The code: Uploaded with ImageShack.us
(comments are locked)
|
Isn't Right, Use this: var target : GameObject; var boltSpeed : float = 10; function Update() { if(!target) { var TempSearch = GameObject.FindWithTag("enemy"); if(!TempSearch) { Destroy(gameObject, 0.01); print("dead"); } else if(TempSearch) { target = TempSearch; } } else if(target) { transform.LookAt(target.transform); if(gameObject.transform.position != target.transform.position) { gameObject.transform.Translate(Vector3.forward * boltSpeed * Time.deltaTime); } } }
Aug 23 '11 at 11:46 PM
warkarma
Assumed that you were using transform in your script since you had .transform at the end. Just take out the : Transform. Edited my answer.
Aug 23 '11 at 11:48 PM
FTheCloud
Same error
Aug 24 '11 at 12:06 AM
warkarma
Oh I see The Problem. Its when you say target = tempSearch. You cant do that because you're defining the var target as Transform and the var tempSearch as a GameObject. They can't equal eachother because there not the same type. Also at the lookat function, thats when you use the .transform. Changed my answer again, again to show you what it should look like.
Aug 24 '11 at 12:28 AM
FTheCloud
Yey, it works fine now :) Thanks a lot
Aug 24 '11 at 06:09 AM
warkarma
(comments are locked)
|
|
╭━━灬╮╭━━∞╮ ┃⌒ ⌒┃┃⌒ ⌒┃ ╰━━━〇〇━━━〇 Looking forward to your visiting input this URL: ★ http://www.goodshopping100.com ★ The website wholesale for many kinds of fashion shoes, like the nike, jordan, prada, also including the jeans, shirts, bags, hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment., After the payment, can ship within short time. free shipping competitive price any size available accept the pyapal ╭══════════════╮ http://www.goodshopping100.com ╰══════════════╯ exquisite watches 75$ 90X Extreme Fitness System ONLY ONLY 42 $$$$$$$ jordan shoes $ 32 nike shox $ 32 Christan Audigier bikini $ 23 Ed Hardy Bikini $ 23 Sm ful short_t-shirt_woman $ 15 ed hardy short_tank_woman $ 16 Sandal $ 32 christian louboutin $ 80 Sunglass $ 15 COACH_Necklace $ 27 handbag $ 33 AF tank woman $ 17 puma slipper woman $ 30 90X Extreme Fitness System ONLY ONLY 42 $$$$$$$ Believe you will love it. we will give you a big discount Opportunity knocks but once welcome to: ==== http://www.goodshopping100.com ====
(comments are locked)
|


