- Home /
Cube trigger not changing position
Original position of the Cube X: 12 Y: -2 Z: -97 Coded when the NPC hits the cube as a trigger the cube is supposed to change position to
X: -46 Y: -2 and Z: -97
In play mode when the NPC hits the cube trigger the cube position winds up when double clicked while the game is playing:
X -283.9301 Y -20.74133 Z -433.067
This position is not even anywhere near the game view but completely out of range. The intent is to get the NPC to walk around the block. I have dragged the cube to each corner of the block, made note of each position at each corner of the block a total of 15 times but in play game mode the cube still goes to that position that is not even in the game map.
Below is the actual code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NPCDestination : MonoBehaviour { public int trigNum;
void OnTriggerEnter(Collider other)
{
if (other.tag == "NPC")
{
if (trigNum == 4)
{
trigNum = 0;
}
if (trigNum == 3)
{
this.gameObject.transform.position = new Vector3(12, -2, -18);
trigNum = 4;
}
if (trigNum == 2)
{
this.gameObject.transform.position = new Vector3(-47, -2, -18);
trigNum = 3;
}
if (trigNum == 1)
{
this.gameObject.transform.position = new Vector3(-46, -2, -97);
trigNum = 2;
}
if (trigNum == 0)
{
this.gameObject.transform.position = new Vector3(12, -2, -97);
trigNum = 1;
}
}
}
}
Your answer
Follow this Question
Related Questions
Ui follow player fixed position 0 Answers
I need help with a Text Location script (Ho bisogno di aiuto con uno script di posizione del testo) 0 Answers
How can i change position of my character 0 Answers
How do i use a public sealed class to create objects and destroy them ? 0 Answers
How would i make it transform player.position =target.position? 2 Answers