- Home /
my destination change doesn't move from randomx and random z can anyone help??
here my code
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DestinationChange : MonoBehaviour { public int xPos; public int zPos;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Enemy")
{
xPos = Random.Range(64, 431);
zPos = Random.Range(45, 442);
this.gameObject.transform.position = new Vector3(xPos, 1.5f, zPos);
}
}
} ,this my script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DestinationChange : MonoBehaviour { public int xPos; public int zPos;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Enemy")
{
xPos = Random.Range(64, 431);
zPos = Random.Range(45, 442);
this.gameObject.transform.position = new Vector3(xPos, 1.5f, zPos);
}
}
}
Answer by Robotinker · Aug 26, 2021 at 06:10 PM
Use a breakpoint to make sure that your code is being hit.
Possible reasons it wouldn't be working:
The DestinationChange component isn't attached to your player object
The collider for the enemy objects is attached to a game object that doesn't have the tag "Enemy"
The collider for your player doesn't have IsTrigger set to true. If you don't want that to be true, use OnCollisionEnter instead of OnTriggerEnter.
Your answer
