HI , Can someone please help , I Have 2 Javascripts, I am trying to combine the 1st Script Makes the Enemy follow and Look at the Player. The 2nd Script have the Enemy shoot at the Player and also follow the player when the player is in range. But the scripts doesn’t work well together I want to combine them into one script.
Script # 1 ( The Follow Script) ------------------
var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
function Start ()
{
}
function Update ()
{
transform.LookAt(Player);
if(Vector3.Distance(transform.position,Player.position) >= MinDist){
transform.position += transform.forwardMoveSpeedTime.deltaTime;
if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
{
//Here Call any function U want Like Shoot at here or something
}
}
}
Script #2 The shooting script_________________________________________
var player : Transform;
var safeDist : float = 15;
var currentDist : float;
var shooting : boolean = false;
var bulletFab : Rigidbody;
var power : float = 1000;
var shotDelay : float = 1;
function Update () {
currentDist = Vector3.Distance(transform.position, player.position);
if(currentDist < safeDist){
transform.LookAt(player);
if(!shooting) shootStuff();
}
}
function shootStuff(){
shooting = true;
var fwd = transform.TransformDirection(Vector3.forward);
var bulletShot : Rigidbody = Instantiate(bulletFab);
bulletShot.AddForce(fwd * power);
yield WaitForSeconds(shotDelay);
shooting = false;
}