2D follow ia unity 2D with agrorange
C#
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#:
- Title
- show double in textbox c#
- Category
- C#
- Title
- order by C#
- Category
- C#
- Title
- c# storing value in session
- Category
- C#
- Title
- c# download string url
- Category
- C#
- Title
- c# arrays of arrays
- Category
- C#
- Title
- unity array of child objects
- Category
- C#
- Title
- unity detect any key
- Category
- C#
- Title
- razor preview
- Category
- C#
- Title
- get number of sundays in a month c#
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- navigate to another page with an object uwp c#
- Category
- C#
- Title
- csharp first element of array
- Category
- C#
- Title
- c# keyvaluepair
- Category
- C#
- Title
- c sharp split by newline
- Category
- C#
- Title
- how to print statement in c#
- Category
- C#
- Title
- eager loading c#
- Category
- C#
- Title
- cc# sort list with list if ids
- Category
- C#
- Title
- c# random number between 0 and 1
- Category
- C#
- Title
- prefab gets character transform
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- c# loop
- Category
- C#
- Title
- jump script unity 2d
- Category
- C#
- Title
- c# webcam
- Category
- C#
- Title
- unity custom editor save changes
- Category
- C#
- Title
- how to add system.messaging c#
- Category
- C#
- Title
- c# 2 timespan return yesterday
- Category
- C#
- Title
- find mongodb c# with task T
- Category
- C#
- Title
- assign datasource to dropdownlist in c#
- Category
- C#
- Title
- .net core copy file in folder to root
- Category
- C#
- Title
- c# check if string is in array
- Category
- C#
- Title
- C# Into To Tring Debug.Log
- Category
- C#
- Title
- button commandfield commandargument pass textbox
- Category
- C#
- Title
- file picker uwp c#
- Category
- C#
- Title
- c# code snippet template
- Category
- C#
- Title
- animator hash in unity
- Category
- C#
- Title
- math.pow in C# using loop
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- c# EncoderParameter
- Category
- C#
- Title
- unity create a child object
- Category
- C#
- Title
- unity c# get bool from another script
- Category
- C#
- Title
- Net.ServicePointManager.SecurityProtocol .net framework 4
- Category
- C#
- Title
- c# properties
- Category
- C#
- Title
- how to insert into a list c#
- Category
- C#
- Title
- how to make an array in csharp
- Category
- C#
- Title
- c# create array of int
- Category
- C#
- Title
- c# read char
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- c# thread sleep
- Category
- C#
- Title
- c# for loop without increment
- Category
- C#
- Title
- delegate function c#
- Category
- C#
- Title
- convert comma separated string to array c#
- Category
- C#
- Title
- c# timespan
- Category
- C#
- Title
- optional parameter get request c#
- Category
- C#
- Title
- take screenshot in c#
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- how to raycast unit
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- ping with c#
- Category
- C#
- Title
- how to make a datatable in c#
- Category
- C#
- Title
- how to split a string with strings in c#
- Category
- C#
- Title
- c# byte array to bitmap
- Category
- C#
- Title
- c sharp split string
- Category
- C#
- Title
- c# serialize
- Category
- C#
- Title
- c# class to byte array
- Category
- C#
- Title
- visual studio c# mark class deprecated
- Category
- C#
- Title
- unity 2d detect click on sprite
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- c# new list object
- Category
- C#
- Title
- verifyusertokenasync password reset token
- Category
- C#
- Title
- asp.net textarea disable resize
- Category
- C#
- Title
- C# array index tostring
- Category
- C#
- Title
- unity how to add a bullet impact force
- Category
- C#
- Title
- c# check if argument null
- Category
- C#
- Title
- unity rigidbody constraints
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- c# loop datatable rows
- Category
- C#
- Title
- C# enum
- Category
- C#
- Title
- Length = '((System.Net.RequestStream)RequestStream).Length' threw an exception of type 'System.NotSupportedException'
- Category
- C#
- Title
- how to pause physics in unity c#
- Category
- C#
- Title
- unity quaternion
- Category
- C#
- Title
- decimals not stored in azure tables
- Category
- C#
- Title
- viewBag as a list
- Category
- C#
- Title
- how to add a list to observablecollection in c#
- Category
- C#
- Title
- c# AllowSynchronousIO to true
- Category
- C#
- Title
- how to make a for loop in c#
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- c# compile into an exe
- Category
- C#
- Title
- if statement conditions c#
- Category
- C#
- Title
- unity 2d joystick controls
- Category
- C#
- Title
- c sharp check if list contains
- Category
- C#
- Title
- winforms c# add data to datagridview with a button
- Category
- C#
- Title
- c# group array based on first character
- Category
- C#
- Title
- c# round number down
- Category
- C#
- Title
- c# how to open file explorer
- Category
- C#
- Title
- asking for user input integer c#
- Category
- C#
- Title
- c sharp create dictionary
- Category
- C#
- Title
- c# to vb.net
- Category
- C#
- Title
- interpolate rotation unity3d
- Category
- C#
- Title
- how to see if they are aholding down a key unity
- Category
- C#
- Title
- c# try catch error
- Category
- C#