Graphics Reference
In-Depth Information
11.10 Weapons and Projectiles
The main weapon (a prefab named Blaster) has a gun mesh with a single script attached to
it—BaseWeaponScript.cs—and it contains a reference to a projectile named Blast that will
be instantiated whenever it fires.
The projectile is made from a cube, colored red to look more like laser fire. Attached
to the projectile are several scripts:
Automatic Destroy Object
Destroys the gameObject after a set amount of time (to stop any projectiles
that never hit anything from travelling off into infinite space!).
Projectile Controller
As discussed in full in Chapter 6.
Rigidbody
The rigidbody has only 0.1 mass and no drag at all. The rigidbody is set to
interpolate its movement (in an attempt to help improve collisions). One other
point of note is that its collision method is set to Continuous. When projectiles
are moving as quickly as they do in this game, it is very probable that they will
sometimes go through other meshes with no registered collision. The Continuous
collision setting will mean increased accuracy but at a small processing cost. In
a game like this, the difference in performance is negligible but you should use
continuous collisions sparingly and as little as possible.
Sphere Collider
The collider is a standard sphere collider.
11.11 User Interface
The main script looks like this:
using UnityEngine;
using System.Collections;
[AddComponentMenu("Sample Game Glue Code/Laser Blast Survival/In-Game UI")]
public class UI_LBS : BaseUIDataManager
{
public GameObject gameOverMessage;
public GameObject getReadyMessage;
void Awake()
{
Init();
}
Search WWH ::




Custom Search