Search Unity

Adding FPS to NavMesh Script

Discussion in 'Scripting' started by herman111, Jul 25, 2015.

  1. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    OK, using this generic code for enemies...problem is, the Unity 4.6 FPS character controller, can't be added to the enemy PreFab....it works if I add it in the hieracharcy....but won't work from a prefab, that I want to spawn.How do I fix this?


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class navmesh : MonoBehaviour {
    5.     NavMeshAgent agent;
    6.     public Transform target;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.         agent = GetComponent<NavMeshAgent>();
    11.             }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.         agent.SetDestination(target.position);
    16.     }
    17. }
     
  2. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    nevermind figured it out
    Code (CSharp):
    1. player = GameObject.FindGameObjectWithTag ("Player").transform;
     
    Last edited: Jul 30, 2015