How to slow character down when moving into a specific area(tilemap?)

Viewed 13

Here is my script to make the character move

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
    Vector3 moveDelta;
    BoxCollider2D boxCollider;
    protected float speed = 2f;
    // Start is called before the first frame update
    void Start()
    {
        boxCollider = GetComponent<BoxCollider2D>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float x = Input.GetAxisRaw("Horizontal"); 
        float y = Input.GetAxisRaw("Vertical"); 
        moveDelta = new Vector3(x,y,0);
        if(moveDelta.x<0)
        {
            transform.localScale = new Vector3(-1,1,1);
        }
        else if(moveDelta.x>0)
        {
            transform.localScale = Vector3.one;
        }
        transform.Translate(moveDelta*Time.deltaTime*speed);
    }
}

I draw a tilemap like this,and I want that when character moves into this area,the speed will be slowed down Here's the image How can I do about this?

0 Answers
Related