hello i did a player to player lock on script it works and my player rotats against the enemys position but i cant seem to make it locked and un locked with the alignment of getkey function i cant unlock it
my script just randomly locks on to the taged enemys and dose not unlock when i press the implememnted button can anyone corrent my script and make it work when i press ctrl buttion and make it unlocked when i [press the same buttion help!..
here is the code of my script help please
using UnityEngine;
using System.Collections;
public class PlayerAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxDistance;
private Transform mytransform;
void Awake() {
mytransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Enemy");
target = go.transform;
maxDistance = 2;
}
private void DeselectTarget() {
target.renderer.material.color = Color.blue;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.R)) {
}
Debug.DrawLine(target.position,mytransform.position, Color.yellow); //Look at target
mytransform.rotation = Quaternion.Slerp(mytransform.rotation, Quaternion.LookRotation(target.position - mytransform.position),rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, mytransform.position) > maxDistance) {
//move towards target mytransform.position += mytransform.forward * moveSpeed * Time.deltaTime;
}
}
}