using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PushForce : MonoBehaviour {
public float pushForce;
public float testRadius;
public float pushRadius;
public Transform forceOrigin;
public GameObject Player;
private GameObject AItarget;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonUp("Fire2"))
{
Collider[] colliders = Physics.OverlapSphere( forceOrigin.position,testRadius);
for(int i = 0; i < colliders.Length; i++)
{
if (colliders*.gameObject != Player)*
{
if (colliders*.gameObject.GetComponent() != null)*
{
GameObject CurrentAItarget;
CurrentAItarget = colliders*.gameObject;*
AItarget = CurrentAItarget;
//Debug.Log(AItarget);
CurrentAItarget.GetComponent().updatePosition = false;
CurrentAItarget.GetComponent().updateRotation = false;
CurrentAItarget.GetComponent<UnityStandardAssets.Characters.ThirdPerson.AICharacterControl>().enabled = false;
Rigidbody rb = colliders*.GetComponent();*
if (rb != null)
{
rb.AddExplosionForce(pushForce, forceOrigin.position, pushRadius, 3.0f);
CurrentAItarget.GetComponent().SetTrigger(“Hit”);
Invoke(“ResetAI”, 0.5f);
}
}
else
{
Rigidbody rb = colliders*.GetComponent();*
if (rb != null)
rb.AddExplosionForce(pushForce, forceOrigin.position, pushRadius, 1.0f);
}
}
}
}
* }*
public void ResetAI()
{
//Debug.Log(AItarget);
AItarget.GetComponent().updatePosition = true;
AItarget.GetComponent().updateRotation = true;
AItarget.GetComponent().SetDestination(Player.transform.position);
}
}