P
P
Pavel Arutyunov2022-04-10 15:28:20
Unity
Pavel Arutyunov, 2022-04-10 15:28:20

How to change the speed of the enemy through the script?

Hello!
I wrote a script for the enemy in which there is a speed parameter. I would like that when the Player entered the zone of action of the trigger, the speed parameter changed, for this I wrote the Script, but did not understand how to change the speed parameter.
Help me please!
The script itself:

void Start()
{
GetComponent();
}

private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("Player"))
{
Change enemy's float Speed ​​parameter.
}
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2022-04-10
@GLaWA_RaKoB

You make an enemy script variable and when necessary you access it, and then through the dot a variable and change it
(the public variable should be)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question