• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

117 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is IComparable, CompareTo function, and ArrayList.Sort() 2 Answers

Set public gameobject by raycast hit target 1 Answer

my script was written but does not want to work 1 Answer

Displaying a different sprite depending on which angle a character is viewed from 1 Answer

Set Bool to false after seconds? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges