- Home /
How do i make a panel question appear when my FPSController walks through a tigger collider?
I make the characters after the collision with the cube, the screen appears "panel question", if you select "button true", the cube destroyed. if selected "button false" then return to the screen "play game".
I'm fairly new to coding in general, working in C#.
you what you want is that you solve all the script from a menu of questions. I could give guidelines I can make per ono whole script that point if you do not learn.
I did a menu containing the components in question canvas. But when writing code for collision cube to shift to the canvas is not. :(
I have tried to create your code and simply syntax "QuesScriptReference.InGame ()" does not work in anything. I'm not very expert but you want to get to do or what condition you want to activate your input
The first thing you should do as a beginner:
Split your problem into the important parts:
You want something (UI Panel) to appear when something(FPSController) touches a trigger zone (Collider).
Let's do a search: https://www.google.com/?gws_rd=ssl#safe=off&q=unity+how+to+activate+a+gameobject+on+trigger+c%23
Let's see some of the results:
Activating GameObjects: https://unity3d.com/learn/tutorials/topics/scripting/activating-gameobjects
Having Colliders trigger something: https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
A question containing an solution to your's: http://answers.unity3d.com/questions/523959/activate-gameobject-that-is-deactivated-with-c.html
Additionally let's read up on the Unity UI System, because I believe you can do what you wanted just by using the OnClick Events of the UI:
http://unity3d.com/learn/tutorials/topics/user-interface-ui
That should be all you need. If you have any questions/problems with that, feel free to ask.
Pro Tip: Search for your problem on google, 80% of beginner problems and questions are answered already. If you can't find any answers there, then it's time to ask on the forums ;)
I did a search on google but could not find the desired answer. And I have written many times to try code without success :(
Here is my code file questionScript:
$$anonymous$$enuScript quesScriptReference;
void Start () {
quesScriptReference = GameObject.Find ("$$anonymous$$enu").GetComponent<$$anonymous$$enuScript> ();
}
void OnTriggerEnter(){
if (quesScriptReference.inGame()) {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) ||
Input.Get$$anonymous$$ouseButtonDown(0)) {
quesScriptReference.quesGame();
}
}
}
The menuScript is the code menu: `public class $$anonymous$$enuScript : $$anonymous$$anagerBase{
public GameObject menuPanel;
public GameObject rulePanel;
public GameObject exitPanel;
public GameObject quesPanel;
public Text nameGame;
public Light dayLight;
public $$anonymous$$aterial tile$$anonymous$$at;
public Image fader;
float timer;
float timerInterval = 0.3f;
float fadeTimer;
float fadeInterval;
Color col;
Color camColor;
Color camColorBlack;
float camLerpTimer;
float camLerpInterval = 1f;
bool camColorLerp = false;
int direction = 1;
Color[] tile$$anonymous$$atDay;
Color tile$$anonymous$$atNight;
int actTileColor;
float daytimeTimer;
float dayTimeInterval = 15f;
public enum GameState {
fadeblackout,
menu,
game,
ques1,
exit,
};
public GameState gameState;
void Awake() {
camColor = new Color (0.75f, 0.75f, 0.75f);
camColorBlack = new Color (0, 0, 0);
actTileColor = 0;
tile$$anonymous$$atDay = new Color[3];
tile$$anonymous$$atDay[0] = new Color (10/256f, 139/256f, 203/256f);
tile$$anonymous$$atDay[1] = new Color (10/256f, 200/256f, 20/256f);
tile$$anonymous$$atDay[2] = new Color (220/256f, 170/256f, 45/256f);
tile$$anonymous$$atNight = new Color (0, 8/256f, 11/256f);
tile$$anonymous$$at.color = tile$$anonymous$$atDay [0];
gameState = GameState.fadeblackout;
menuPanel.SetActive (true);
rulePanel.SetActive (false);
exitPanel.SetActive (false);
quesPanel.SetActive (false);
}
void Update () {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Escape)) {
if (gameState == GameState.game)
Time.timeScale = 0;
gameState = GameState.exit;
exitGame();
}
switch (gameState) {
case GameState.fadeblackout:
col = fader.color;
col.a -= 0.01f;
if (col.a <= 0) {
col.a = 0;
fader.gameObject.SetActive(false);
gameState = GameState.menu;
}
fader.color = col;
break;
case GameState.menu:
break;
case GameState.game:
timer += Time.deltaTime;
if (timer >= timerInterval) {
timer -= timerInterval;
}
daytimeTimer += Time.deltaTime;
if (daytimeTimer > dayTimeInterval) {
daytimeTimer -= daytimeTimer;
camColorLerp = true;
camLerpTimer = 0;
}
if (camColorLerp) {
camLerpTimer += Time.deltaTime;
float percent = camLerpTimer / camLerpInterval;
if (direction == 1) {
Camera.main.backgroundColor = Color.Lerp (camColor, camColorBlack, percent);
tile$$anonymous$$at.color = Color.Lerp (tile$$anonymous$$atDay [actTileColor], tile$$anonymous$$atNight, percent);
dayLight.intensity = 1 - percent;
} else {
Camera.main.backgroundColor = Color.Lerp (camColorBlack, camColor, percent);
tile$$anonymous$$at.color = Color.Lerp (tile$$anonymous$$atNight, tile$$anonymous$$atDay [actTileColor], percent);
dayLight.intensity = percent;
}
if (percent > 0.98f) {
camLerpTimer = 1;
direction *= -1;
camColorLerp = false;
if (direction == -1)
actTileColor = Random.Range (0, tile$$anonymous$$atDay.Length);
}
}
break;
case GameState.ques1:
break;
}
}'
public bool inGame() {
if (gameState == GameState.game)
return true;
else
return false;
}
public void playGame() {
menuPanel.SetActive (false);
gameState = GameState.game;
}
public void showRules() {
menuPanel.SetActive (false);
rulePanel.SetActive (true);
}
public void exitGame() {
menuPanel.SetActive (false);
exitPanel.SetActive (true);
}
public void exitRules() {
menuPanel.SetActive (true);
rulePanel.SetActive (false);
gameState = GameState.menu;
}
public void quitGame() {
Application.Quit ();
}
public void quesGame (){
gameState = GameState.ques1;
quesPanel.SetActive (true);
}
public void respondQues(){
Destroy (transform.gameObject);
quesPanel.SetActive (false);
gameState = GameState.game;
}
public void ques1(){
quesPanel.SetActive (false);
gameState = GameState.game;
}
public void ques2(){
quesPanel.SetActive (false);
gameState = GameState.game;
}
}
How to show a questions ( text,button) UI Canvas after collider? I've tried a lot of ways but it's not.
Answer by BrkTbn · Jul 27, 2016 at 10:54 AM
Create your panel in regular Canvas, create button functionality and stuff. Then disable it via the checkbox on top of the inspector. Then in your script, make a public variable and set it to your panel gameobject in the inspector. Use panel.SetActive( true ) to make it visible.
//......
public GameObject questionPanel
void OnTriggerEnter(Collider col)
{
if(col == yourCube)
{
questionPanel.SetActive(true);
}
}
//......
Answer by PhantomSarcasm · Jul 27, 2016 at 08:31 PM
Forgiving, the video does not have audio, English is not talking, esplique as I could along agoogle translator.
also I leave the project for you to look better next to the video:
https://docs.google.com/uc?id=0BzO4uF3w3jGweGlQRk9wUHNNdjg&export=download
link video : (I'm still climbing youtube)-better download
https://docs.google.com/uc?id=0BzO4uF3w3jGwb01YSTNfRDlHM0U&export=download
I am using a switch to create multiple questions and do not use many sprits; but one. Agragar more questions for saumenta the "case" but this last-always have to be the last one cambiale the number to "case"
case 3:
or
case 4:
//QUESTION
break;
I send my demo. Can you help me fix?q
Variable-the info is to place the question. -the delegate is to add functions to buttons. -to add more questions just you have to Agragar the "case". - Seeks to make the last "case" only appends more. - The others are static functions that are in the other script.
why you send the project so you could read it, so you understand more.
reviews the "quest" script.
Your answer
![](https://koobas.hobune.stream/wayback/20220612085513im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Use sprite mesh for filled image 1 Answer
help with small problem,Question about adding 0 Answers
Pinch zoom on UI image 2 Answers
Look left or right line will disable 0 Answers
How do you access the Blocking Mask of GraphicsRaycaster in code? 2 Answers