Question by
Timothy_van_de_Bilt · Aug 24, 2017 at 10:30 AM ·
scripting beginnerscriptingbasics
Pointing arrow to next position
Hi there, I am a unity noob trying to add a simple pointing arrow to the next node position in this scriot. can anybody hep me create a serialized field within this script where i put the arrow that is within the VR field that just points to the next poistion (like google streetview).
i know that i should use the LookAt. but i dont know how to add it to the script. i hope somebody can help me.
using System;
using UnityEngine;
using System.Collections;
using System.Linq;
public class GameHandler : MonoBehaviour {
[HideInInspector]
public int currentPositionID = 0;
[HideInInspector]
public GameObject user;
public GameObject node;
//GameObject map, nodetext;
[SerializeField]
private GameObject nodetext;
[SerializeField]
private GameObject map;
[SerializeField]
private GameObject ArrowForward;
[SerializeField]
private GameObject Arrowpointing;
//arrow that points to next node
[SerializeField]
private GameObject ArrowPointForward;
[HideInInspector]
public GameObject[] standpoints;
//[HideInInspector]
public GameObject[] mapNodes;
GameObject _tempobj;
//hard move to node
public int adminNode = -5;
public bool forceNode, triggerobj;
public bool nextNode;
public bool previousNode;
//Node to node menu
GameObject nodeNum;
public GameObject floorMenu;
public bool showNodeMenu;
private bool checkShowNodeMenu = true;
public float nodeResize = 1;
public Vector3 nodeOffset = new Vector3(0, 0, 0);
public bool showMap;
private bool mapShowing = true;
void Start () {
user = GameObject.FindGameObjectWithTag ("Player").gameObject;
//map = GameObject.FindGameObjectWithTag ("map").gameObject;
//nodetext = GameObject.FindGameObjectWithTag("nodepos").gameObject;
standpoints = GameObject.FindGameObjectsWithTag("StandPosition").OrderBy(go => go.name).ToArray();
//nodeNum = GameObject.FindGameObjectWithTag("NodeDisplayNum");
//nodeMenu = GameObject.FindGameObjectWithTag("NodeMenu");
CreateMap ();
UpdateUser ();
}
void Update () {
//If the button in the Unity UI is pressed, change the users position to the specified node
//adminNode = Mathf.Clamp (adminNode, 0, standpoints.Length-1);
if (adminNode >= standpoints.Length)
{
adminNode = 0;
}
else if (adminNode < 0)
{
adminNode = standpoints.Length;
}
if (forceNode == true) {
UpdatePosition (false, adminNode);
forceNode = false;
}
if (nextNode == true) {
UpdatePosition (true, 2);
nextNode = false;
}
if (previousNode == true) {
UpdatePosition (true, 1);
previousNode = false;
}
//If the button in the Unity UI switches, show or hide the node buttons
if (showNodeMenu != checkShowNodeMenu)
{
checkShowNodeMenu = !checkShowNodeMenu;
NodeMenu(checkShowNodeMenu);
}
//Toggle the map on and off
if (mapShowing != showMap)
{
mapShowing = !mapShowing;
showHideMap(mapShowing);
}
}
public void CreateMap () {
//Create the array for the mapnodes
mapNodes = new GameObject[standpoints.Length];
//Create the nodes on the map and put them in the array
for (int i = 0; i < standpoints.Length; i++) {
_tempobj = (GameObject)Instantiate (node, Vector3.zero, Quaternion.identity);
_tempobj.transform.parent = map.transform;
_tempobj.transform.localPosition = standpoints [i].transform.localPosition;
_tempobj.transform.localPosition *= nodeResize;
_tempobj.transform.localPosition += nodeOffset;
_tempobj.transform.localEulerAngles = new Vector3(-7, 0, 0);
_tempobj.GetComponent<MapNode> ().myID = standpoints [i].GetComponent<StandingPlace> ().myID;
_tempobj.GetComponent<MapNode>().myFloor = standpoints[i].GetComponent<StandingPlace>().myFloor;
_tempobj.transform.localScale = new Vector3 (0.05f, 0.05f, 0.05f);
_tempobj.name = "node " + standpoints [i].GetComponent<StandingPlace> ().myID;
_tempobj.transform.GetChild (0).GetComponent<TextMesh> ().text = "" + standpoints [i].GetComponent<StandingPlace> ().myID;
mapNodes[i] = _tempobj.gameObject;
standpoints[i].gameObject.GetComponent<MeshRenderer>().enabled = false;
}
}
//Update the nodes on the map to only show the nodes for the floor you're currently on
public void UpdateMap(int floor)
{
for (int i = 0; i < mapNodes.Length; i++)
{
//Debug.Log("Test node: " + mapNodes[i]);
//Debug.Log("Node component: " + mapNodes[i].GetComponent<MapNode>());
mapNodes[i].GetComponent<MapNode>().UpdateMap(floor);
}
}
//true if button calls, pos is either stand ID or +1/-1 if button
public void UpdatePosition (bool button, int pos) {
if (button == true) {
if (pos == 1) {
currentPositionID -= 1;
} else {
currentPositionID += 1;
}
if (currentPositionID < 0) {
currentPositionID = standpoints.Length -1;
}
if (currentPositionID >= standpoints.Length) {
currentPositionID = 0;
}
}
if (button == false) {
currentPositionID = pos;
}
UpdateUser ();
GetComponent<FloorHandler>().ChangeFloor(standpoints[currentPositionID].GetComponent<StandingPlace>().myFloor);
}
//places user at the new location by fading in and out
void UpdateUser () {
int selection = currentPositionID;
//Debug.Log(selection + " " + standpoints.Length);
user.transform.position = standpoints [selection].transform.position;
nodetext.GetComponent<TextMesh> ().text = "" + selection;
}
//Hide or show the node-buttons beneath the virtual tablet
void NodeMenu(bool showMenu)
{
floorMenu.SetActive(showMenu);
}
void showHideMap(bool show)
{
//gameObject.SetActive(show);
map.gameObject.SetActive(show);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612133434im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Timer wont work 0 Answers
Getting weird error message!?!?!? 1 Answer
Make enemy patrol without Nav Points? 0 Answers
tagged objects problem 0 Answers