- Home /
How to make speed changed in js
i know, this is very simple. First off, this is not going to be attached to my Enemy but i want to know if its possible to change the navmeshspeed from a script to my enemy. It is named "OGRE". I need this script converted into Javascript, and i need it to somehow do it remotely without attach the script to the enemy.
Need this converted and remotely change speed:
GetComponent<NavMeshAgent>().speed = 6f;
Yes, I don't know if its possible. Yes my "Enemy" is named "OGRE". it would be very awesome if you could respond fast. Thanks!
Full script:
#pragma strict
var coinValue = 1;
function OnTriggerEnter(info: Collider)
{
if (info.name == "Player")
{
GameMaster.currentScore += coinValue;
Destroy(gameObject);
GetComponent<NavMeshAgent>().speed = 6f; // <---- Need this converted remotely!
}
}
I don't really understand what you are saying.
Do you want to change the speed of your player or the enemy?
Who will be responsible for changing the speed value?
When does the change will occur?
Where will the script be attached?
I am using Nav$$anonymous$$esh to controll the enemy, and i need to change that speed. The script is attach to another object called "Letter". I need to control the speed of the Navmesh / AI to make it go fast/slow.
Answer by Hellium · Jan 22, 2018 at 04:03 PM
In your script attached to the desired object, declare a public NavMeshAgent
var agentToControl : NavMeshAgent;
In the Unity Editor, drag & drop the gameobject holding the NavMeshAgent
component that must be controlled by your 1st script.
Then, you just have to change the value as you want.
function ChangeAgentSpeed()
{
agentToControl.speed = 6f ;
}
Your answer
Follow this Question
Related Questions
How can I implement a SimpleMove max speed? 1 Answer
error with maxbackwardsSpeed 1 Answer
Control animation speed with slider 4 Answers
Navmesh wandering how do you do that? 2 Answers