- Home /
Equip in-game map item
Currently I am working on a game using the Oculus rift and we need a map system, so I am building a physical map the player can pull out and look at in-game.
I'm having a great deal of trouble scripting a way to pull out the map and put it away with the same key stroke. I can't seem to get the code right in C#. :[
Any help is appreciated.
Answer by bubzy · Jul 18, 2013 at 05:38 PM
using UnityEngine;
using System.Collections;
public class mapToggle : MonoBehaviour {
// Use this for initialization
bool mapOut = false;
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.M))
{
toggleMap();
}
}
void toggleMap()
{
mapOut = !mapOut;
}
void OnGUI()
{
if(mapOut)
{
GUI.Label(new Rect(0,0,200,100),"MAP IS OUT!");
}
else
{
GUI.Label(new Rect(0,0,200,100),"MAP IS NOT OUT!");
}
}
}
Updated in actual working code. please try though to learn this stuff yourself, maybe find some basic c# tutorials, you will NEVER finish a project by asking here everytime you get stuck. good luck with your project :)
I understand that this is a 'working' code, but this is not solving my issue. The only thing that is happening is the broadcast of $$anonymous$$AP IS OUT or $$anonymous$$AP IS NOT OUT.
I want to pull up a in-game psychical map to look at and put away.
i think you need to learn some more coding then, this DOES EXACTLY what you need, but you have to code the map in and out yourself, its a framework to build on. if you cannot do this yourself, then perhaps you should start with a more basic project and work your way up. I mean, I don't have your resources, your model files, how the map looks, what happens when the map is up, I don't have the names of the other objects in your scene or how to interact with them. there is a lot to consider, and please don't ask other people to write your game for you, aside from anything else (and that no one would do it), you totally lose any satisfaction of completing your own project. my answer is still correct though.
I ended up fixing it and making it work, though I did change the coding you gave me.
No reason to be rude, I wasn't asking you to write my $$anonymous$$ms game for me. Just a simple structure to go by so I could learn more.
Code for reference:
using UnityEngine;
using System.Collections;
public class mapToggle : $$anonymous$$onoBehaviour {
// Use this for initialization
bool mapOut = false;
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$))
{
// toggle visibility:
renderer.enabled = !renderer.enabled;
}
}
}
wasn't trying to be rude mate :) sorry if it came across that way.
by the way, that Boolean value (mapOut) wont be required unless you are using it in another point of your code.
Your answer
Follow this Question
Related Questions
is it possible to make the player to transform into a differet object? 0 Answers
spawn object on keypress c# 2 Answers
Make a rigidbody sphere stop while moving fast 2 Answers
Grapple gun help 1 Answer
Switch from GUI button to toggle key 1 Answer