Game Development Reference
In-Depth Information
// C# user:
using UnityEngine;
using System.Collections;
public class AI : CharacterClass {
public float shotRange = 15.0f;
public float playerRange = 5.0f;
public float distanceToShot = 10.0f;
public float walkingTime = 6.0f;
public float thinkingTime = 3.0f;
public CSharp.WaypointsContainer waypointsContainer;
float _lastTime = 0f;
float _angle;
float _angleVelocity;
bool _isThinking;
protected override void Start () {
base.Start();
if (laser != null) {
laser.gameObject.SetActive(false);
laser.SetPosition(1,new
Vector3(0f,0f,GUN_LASER_DISTANCE));
}
}
}
With the preceding code, we basically created all the necessary parameters for the
AI script. We also override the start function and set the laser length on the y -axis,
which is a bit different to our CharacterControl script in Chapter 5 , Build a
Rocket Launcher! .
3. Next, we will create four functions to give our enemy a personality and make it
smarter:
◦ The first function is the CanShoot() function, which will make the en-
emy shoot when the player is within their shooting range by checking the
distance of the player and enemy. We will also use the Phys-
ics.Raycast() function to see if there is anything blocking the direc-
Search WWH ::




Custom Search