Game Development Reference
In-Depth Information
//find distance between object and player
var dist = Vector3.Distance(playerPos.position, gameObjPos);
//find the horizontal distances along the
//x and z between player and object
var dx = playerPos.position.x - gameObjPos.x;
var dz = playerPos.position.z - gameObjPos.z;
//determine the angle of rotation between the
//direction the player is facing and the location
//of the object
deltay = Mathf.Atan2(dx, dz) * Mathf.Rad2Deg − 270 −
playerPos.eulerAngles.y;
//orient the object on the radar according to the
//direction the player is facing
radarSpotX = dist * Mathf.Cos(deltay * Mathf.Deg2Rad) *
mapScale;
radarSpotY = dist * Mathf.Sin(deltay * Mathf.Deg2Rad) *
mapScale;
//draw a spot on the radar
GUI.DrawTexture(Rect(radarWidth/2.0 + radarSpotX,
radarHeight/2.0 + radarSpotY, 2, 2),
spotTexture);
}
function DrawSpotsForOrbs()
{
var gos : GameObject[];
//look for all objects with a tag of orb
gos = GameObject.FindGameObjectsWithTag("orb");
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos)
{
DrawRadarBlip(go,orbspot);
}
}
Step 3. Attach the script to the Main Camera, which is a child object
of the Hero game object.
Step 4. Locate the OrbPrefab in the Orb folder in the Project. Create a
tag for this prefab and call it orb . Ensure that after creating the tag it is
assigned to the OrbPrefab in the Inspector.
Step 5. In order to draw radar blips on the HUD, you will need to
create a texture. This need only be a very small texture of a single
color as it will only take up one pixel on the screen. Create a .png
Search Nedrilad ::




Custom Search