2D follow ia unity 2D with agrorange
using UnityEngine;
using System.Collections;
public class badbox : MonoBehaviour
{
public Transform target;//set target from inspector instead of looking in Update
public float speed;
public float distance;
public float agroRange;
void Start()
{
}
void Update()
{
if (Vector3.Distance(transform.position, target.position) < agroRange) //Agro range
{ //rotate to look at the player
transform.LookAt(target.position);
transform.Rotate(new Vector3(0, -90, 0), Space.Self);//correcting the original rotation
}
if (Vector3.Distance(transform.position, target.position) < agroRange) //Agro range
{ //move towards the player
if (Vector3.Distance(transform.position, target.position) > distance)
{//move if distance from target is greater than distance
transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0));
}
}
}
}
Also in C#:
- how to add movement in unity
- c# linq select specific columns
- send type as argument c#
- unity line renderer position count
- c# two dimensional array
- csharp first element of array
- c# count number of occurrences in string
- c# timespan
- how to add system.messaging c#
- 2D follow ia unity 2D with agrorange
- get normal from 3 points
- c# how to delete a file
- iterate through dictionary c#
- unity how to get transform scale
- c# dictionary literal initializer
- how to convert int to string unity c#
- c# skip following code in loop
- c# loop through list
- .net core authorizationhandlercontext
- xarray: create 2d dataset
- find gameobject with tag
- comments unity c#
- visual studio clear text script
- Update data in db .net