Skip to main content

052. Unity3d Tutorial - Targetting 2.0 2/3

See video

Unity3d game engine is the game development tool we will work with today as we continue our trek to becoming a game programmer. In this episode of our Hack And Slash tutorial, we continue improving our targeting system by enabling it to toggle our 3d text on and off. We will also code in a function or two, too have the the 3d text get the name of the mob that we will have stored in our Mob class, and change it's text property to display the it.

I have been having problems with the auto complete in the new version of Mono Development, and the old version of Unity3d. I have decided to upgrade my project to the latest version of Unity3d 3.0 as I have not had any problems with the auto complete in Mono Development. I am glad to say that there was no problem upgrading the project to the newer version.

The new version should be made public soon. When it does go live, we will all upgrade our projects and make sure there are no compatibility issues. If there are, we can go over them together and sort out the bugs. The joys of becoming a game programmer.

Tags:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Offline
Joined: Aug 20 2011

Hi I'd like to firstly say thanks for your hard work for this wonderful collection of video tutorials.

I'm new to the unity community and has been having troubles with getting this targetting script to work. I've been converting all of your C+ to Javascript to help me better understand what's happening and engaging my mind more than just a simple copy and paste.

What's happening in my game is that when I target, it shows 1 of my mob's name, then it doesn't for the rest. But the moment I remove the mob with the visible name (through interactive playthrough), I'm able to get a different mob's name to appear. Through some debugging I've found that the "name" does not change, it stays at the child of same monster thoughout, but through more debugging I've found that the "name" would change to the next monster, but when told to find the child, if goes and finds the child of the first monster, hence an endless cycle of making the first mob's name visible. I hope you can help me figure this out (and I hope this is the right place to comment).

The coding I used for that section is:

public var selectedTarget: GameObject;

function SelectTarget(){

var animationScript = gameObject.GetComponent(AnimationScript);
animationScript.target = selectedTarget.gameObject;

var enemyName: GameObject;

// helped me discover that enemyName does indeed change to selectedTarget
// but the child does not follow with it
// enemyName = selectedTarget;
// enemyName.GetComponent(MeshRenderer).enabled = true;

enemyName = selectedTarget.Find("Name");
enemyName.GetComponent(MeshRenderer).enabled = true;
}

I've uploaded it if you want to see what I meant with the names not showing up (Left Shift for target switching, and LMB/MMB/RMB for attacking.
http://thedistantvoice.com/WebPlayer/NEW_Aug20/WebPlayer.html

StephanLome's picture
Offline
Joined: Sep 23 2011

Seems like you're typecasting with () rather then <> in this line:

enemyName.GetComponent(MeshRenderer).enabled = true;

Hope that helps.

-StephanLome

Offline
Joined: Dec 7 2011

Hi I have this error can someone helpme please?

When I hit tab key this error came out and the game pause

NullReferenceException: Object reference not set to an instance of an object
TargetMob.SelectTarget () (at Assets/scripts/TargetMob.cs:89)
TargetMob.TargetEnemy () (at Assets/scripts/TargetMob.cs:66)
TargetMob.Update () (at Assets/scripts/TargetMob.cs:105)

the line 89 is this

name.GetComponent<>().text = selectedTarget.GetComponent<>().Name;

inside the first <> TextMesh

and the second <> Mob

Thanks

Offline
Joined: Apr 22 2012
// EDIT I have clear my error self. GameMaster.cs ************* (Line 51) LoadCharacter(); Was the Error it was a fail Line