Quantcast
Channel: Questions in topic: "if-else"
Browsing latest articles
Browse All 133 View Live

How to tell if the code flow changed

Alright, so this is something I've never quite figured out how to do efficiently. You could have: bool last; //true = was last in the if statement //false = was last in the else statement if (/*not...

View Article



Randomly choosing between 3 options

Basically i want the character to either jump up and left, up and right or just straight up. Sorry if it' simple to do, i'm new to this Here is my code so far: if (Random.Range(0, 2) == 0)...

View Article

Using a lot of calls and if else statement, is there a better way to do this?

Hi there, I'm still trying to figure out what is the best practice when it comes to game scripting in unity. The script I've done displays different text on UI when a gameobject is detected from...

View Article

Checking nulls almost all the time! Is this normal?

The script I wrote below checks the state of a static variable "selectedObject" from another class, every time I want to access or change things inside this static variable, I have to check the if it...

View Article

Optimising if else statements to switch and enums, or are there better methods?

Hello, I've hard coded 21 bools to check in my if else statements. Currently i want to optimize them with switch and enums. To illustrate, here's an example: void Activate(Stat stat) { if(stat.box ||...

View Article


Unity 5 OnCollisionEnter IF statement not working.

Help.. what's wrong with my script!!! im just trying to make a script that when the player collides with a cube or trigger it will start a function of if statement but never happens here's my script.....

View Article

HELP ME PLEASE TO FIX MY PROBLEM..

Help.. how to use if statement in ui buttons... inside of private void update... Im trying to make a ui buttons inside of the if statement... but is always show in the console edit - projects settings...

View Article

State Machine If Else Distance question (c#)

Hi all. Having a bit of an issue with a state machine script. I need to determine the best way to differentiate between two similar distances for use in If/Else. Default state happens when >...

View Article


If statement not working properly

here is the code `if (level_completed == 1) { string temp = "Level_" + (level_current + 1); Debug.Log(temp); bool temp1 = PlayerPrefs.HasKey("temp"); Debug.Log(PlayerPrefs.GetInt("temp"));...

View Article


How to pass a parameter only if certain condition is true?

I have a script that's getting a bit messy: float value = MGS.Math.PercentOf(current_health, 0, max_health, min_color, max_color); if (red && !blue && !green)...

View Article

Simple toggle not working

public GameObject canvasInstr; private bool instr = false; void Start () { canvasInstr.SetActive(false); } void Update () { if(Input.GetKeyDown(KeyCode.I) && !canvasInstr){...

View Article

if a string contains any string

I want to do if first child's string contains any child's string, then enable colliders of these same strings. For example: zero element's string and (what if) fourth element's string are same. then...

View Article

RaycastHit if/else Problem (bug?)

So, I'm using Raycasts to detect whether something is in front of me. And I have this simple code: if (Physics.Raycast (playerCam.transform.position, playerCam.transform.forward, out hit)) { print...

View Article


What's wrong code if-else with tag script ?

Hello I have the right panel and the wrong panel, the panel is used to check whether the object is dragging and dropping in the right slot. but in this code, when I run the wrong panel it always...

View Article

GameObject return if, else

I am having difficulties creating a GameObject class, basically what I want is for unity to stop throwing errors when the powerUpPrefabs array is empty and ideally print out a debug.log saying that the...

View Article


Change the scale with OnCollisionEnter once

When my player collided with a button"GAMEOBJECT" change the scale to big and the button is actived When i collide again change my player scale to small and the button is disabled. How can i do that?...

View Article

How ifs work?

Okay, I'm really tired of this damn if statments, 96 out 100 times it wont work -.- . Can please someone explain how if's work? Because here I have an example. In this code the ray of my enemy detects...

View Article


I want just animate only one robot when his button is pressed. Problem: that...

using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Vuforia; public class vb_robotsbuttons : MonoBehaviour, IVirtualButtonEventHandler{ public GameObject...

View Article

Any way to slim down if/else statements?

Hi! Anyone know a way to slim this code down a bit? Code example below: using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimationManagement : MonoBehaviour {...

View Article

why is my jump script not working?

So I have this script set up that references another script to sense the character's current power level to check if flying is available instead of jumping, and now I can't jump OR fly. Here it is:...

View Article

Questions about the event system in unity.

Good morning all , About the event system in C # and unity: -I currently find it very difficult to assimilate and understand my course on delegates and event systems in C # which is quite complicated...

View Article


If/else statement is always else

I was coding more stuff and needed to make an if/else statement. But the statement always evaluates to else. Both variables are set randomly but the contents of redArray are the same every time the...

View Article


Trigger on collider if another collider is in field of view

I try to trigger a UI on collision with object A, if object B is in sight (of first person player). The collision with object A already works, but I don't know how to implement the combination of...

View Article

So I'm very new at Unity and I tried to improvise the controllers with if...

I tried to use the old Input.GetAxisRaw("Horizontal") and Vertical but it didn't work quite well, my character was teleporting upwards everytime i moved it, so I used this if method and it works, but i...

View Article

check if my variable is in the same position as the array

Hey guys, I'm developing object inspection script the idea is when I press (E) on the object, the dialog box appears, and take the first string and paste it into the text object in my scene, and if (E)...

View Article


How to shift the player to a definite position in the x-axis using key presses?

I am essentially trying to create a subway surfers game for a project. So the plane is divided into three tracks. Left, Middle, Right. If the player is at right, I want to move the player to the middle...

View Article

If else block acts extremely weird

Hello, I've created an if else block. but if condition does not get true, but I'm %100 sure it's true. Is this because encoding of letters? And code enters to if at the first if in foreach loop, I...

View Article

It keeps telling me ( error CS1525: Unexpected symbol `else' ) and I can't...

int x=int.Parse(Console.WriteLine("what's the first side? ")); int y=int.Parse(Console.WriteLine("what's the second side?")); int z=int.Parse(Console.WriteLine("what's the third side?")); if (x+y>z...

View Article

if else statement not working???

Everything was working perfectly fine in my project until I changed the condition slightly through the code. Even if i didn't do it right somehow, that's not what it's giving me errors for, but...

View Article



Double-tap a key to sprint and to not sprint?

Hello, I am creating a sprinting system and I need help making it so when you double tap the control key, you can sprint automatically without holding it. Then when you press control again once, you...

View Article
Browsing latest articles
Browse All 133 View Live




Latest Images