Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity 2d enemy patrol script

public class PatrollingWallToWall : MonoBehaviour
{
    public float mMovementSpeed = 3.0f;
    public bool bIsGoingRight = true;

    private SpriteRenderer _mSpriteRenderer;

    // Start is called before the first frame update
    void Start()
    {
        _mSpriteRenderer = gameObject.GetComponent<SpriteRenderer>();
        _mSpriteRenderer.flipX = bIsGoingRight;
    }

    
    void Update()
    {
        // if the ennemy is going right, get the vector pointing to its right
        Vector3 directionTranslation = (bIsGoingRight) ? transform.right : -transform.right; 
        directionTranslation *= Time.deltaTime * mMovementSpeed;

        transform.Translate(directionTranslation);


        //CheckForWalls();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# list find index 
Csharp :: c# export datatatble to excel 
Csharp :: unity master volume changer 
Csharp :: vb.net check if datatable has rows 
Csharp :: convert c# string to int 
Csharp :: string.QueryString c# 
Csharp :: concatenation in c# 
Csharp :: return stream from file c# 
Csharp :: how to fix on GetMouseButtonDown activating UI unity 
Csharp :: serilog .net 6 
Csharp :: for jump script unity 2d 
Csharp :: convert list string to list enum c# 
Csharp :: get mouse inpuit new input system 
Csharp :: c# map function 
Csharp :: Get all images from folder asp.net 
Csharp :: how to add skybox in unity 
Csharp :: how to write web service for API in c# 
Csharp :: C# The request was aborted: Could not create SSL/TLS secure 
Csharp :: c# usermanager update user 
Csharp :: how to query items with any id in a list of ids linq c# 
Csharp :: c# Remove String In C# 
Csharp :: spin with rigidbody 2d unity 
Csharp :: c# invokerequired wpf 
Csharp :: Show empty message in data table angular material, If no data found 
Csharp :: c# Sum of all the factors of a number 
Csharp :: unity2d switch camera 
Csharp :: remove substring from string c# 
Csharp :: vb.net windows version check 
Csharp :: c# decimal to fixed 2 
Csharp :: convert date to days c# 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =