Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to make projectile track and go to specified enemy in unity

using UnityEngine;
using UnityEngine.AI; //using the unity AI system to move the projectile to the enemy using NavMeshAgent


public class missileMovement : MonoBehaviour //name of the script
{

    GameObject enemy; 


    // Start is called before the first frame update
    void Start() //can also be used in Awake()
    {
        enemy = GameObject.Find("BadGuy"); //find the object tagged with a name, in this instance its "BadGuy"

        GetComponent<NavMeshAgent>().SetDestination(enemy.transform.position);  // gets the component of the projectile
      																			//and then setting its destination to follow the position of the enemy
    }
  //you can add anything you want after this, in general this script has to be on the projectile prefab itself.

  void Update()
  {
     GetComponent<NavMeshAgent>().SetDestination(enemy.transform.position);  // gets the component of the projectile
      																			//and then setting its destination to follow the position of the enemy
    
  }
  
  
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: .net core best package for scheduler 
Csharp :: object shaking unity 
Csharp :: qcombobox delegate text filter 
Csharp :: html tag inside razor tag 
Csharp :: how to add a round image unity 
Csharp :: how to pass id to modal in asp.net mvc 
Csharp :: CullingGroup 
Csharp :: How to use C# to open windows explorer in “select/open file mode 
Csharp :: unity3d spin wheel 
Csharp :: lizzo net worth 
Csharp :: download file c# 
Csharp :: c# textbox tab column 
Csharp :: unity custom editor hide values in dropdown list 
Csharp :: method declaration in c# 
Csharp :: c# inline 
Csharp :: how to split a string in f# 
Csharp :: get first and last item list c# 
Csharp :: photon2 what is a stream 
Csharp :: c# xamarin forms use AssetManager to get text file 
Csharp :: generate prime numbers 
Csharp :: unity how to check object position 
Csharp :: rating iOS game in unity 
Csharp :: how to add default value to combobox in wpf 
Csharp :: run as administrator vs 2019 
Csharp :: inverse kinematics not working unity 
Csharp :: razor: show editable list 
Html :: html 5 default code 
Html :: jquery ui cdn 
Html :: html input not editable 
Html :: link email anchor to open up users email address 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =