Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Someting Wrong

Discussion in 'Scripting' started by takixx, Aug 15, 2018.

  1. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    Sayac1 =

    counting those with a basket

    Sayac2 =
    Counting out

    Question :
    I want to use 7 shots.
    if (Sayac1) counter 3 and more, the new section ( public string LevelPassed) Howewer if(sayac2) counter 5 and more restart game (public string YenidenOyna)

    A FEW NOTE ;
    I gave 7 numbers to "top" but
    something went wrong

    The section was not completed despite having 3 baskets

    howewer.png


    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.SceneManagement;
    7.  
    8. public class Skor : MonoBehaviour
    9. {
    10.    
    11.     public string Menu;
    12.     public GameObject music;
    13.     [SerializeField] private GameObject Image;
    14.     [SerializeField] private GameObject Image2;
    15.     [SerializeField] private GameObject Image3;
    16.     [SerializeField] private GameObject Image4;
    17.     [SerializeField] private GameObject Image5;
    18.     [SerializeField] private GameObject Image6;
    19.     [SerializeField] private GameObject Image7;
    20.     [SerializeField] private GameObject Red;
    21.     [SerializeField] private GameObject Red2;
    22.     [SerializeField] private GameObject Red3;
    23.     [SerializeField] private GameObject Red4;
    24.     [SerializeField] private GameObject Red5;
    25.     [SerializeField] private GameObject Red6;
    26.     [SerializeField] private GameObject Red7;
    27.     private int sayı;
    28.     private int sayac;
    29.     private int sayac2;
    30.     private int top;
    31.     public string LevelPassed;
    32.     public string YenidenOyna;
    33.     private void Start()
    34.     {
    35.         sayı = 0;
    36.         sayac = 0;
    37.         sayac2 = 0;
    38.         top = 7;
    39.         Image.SetActive(false);
    40.         Image2.SetActive(false);
    41.         Image3.SetActive(false);
    42.         Image4.SetActive(false);
    43.         Image5.SetActive(false);
    44.         Image6.SetActive(false);
    45.         Image7.SetActive(false);
    46.         Red.SetActive(false);
    47.         Red2.SetActive(false);
    48.         Red3.SetActive(false);
    49.         Red4.SetActive(false);
    50.         Red5.SetActive(false);
    51.         Red6.SetActive(false);
    52.         Red7.SetActive(false);
    53.     }
    54.  
    55.    
    56.     private void Başarılı()
    57.     {
    58.         if (top == 7 && sayac >= 3)
    59.         {
    60.             Debug.Log("Yeni Level");
    61.             SceneManager.LoadScene(LevelPassed);
    62.            
    63.         }else if(top == 7 && sayac2 >= 5)
    64.         {
    65.                 Debug.Log("Level Başarısız");
    66.                 SceneManager.LoadScene(YenidenOyna);
    67.         }
    68.     }
    69.     void OnTriggerEnter2D(Collider2D other)
    70.     {
    71.         if (other.gameObject.CompareTag("basket"))
    72.         {
    73.             sayac = sayac + 1;
    74.             Debug.Log("Sayac : " + sayac);
    75.             top = top - 1;
    76.             Debug.Log("Top Kalan : " + top);
    77.             Başarılı();
    78.             sayı = sayı + 1;
    79.            
    80.             if (sayı==1 && Red.activeSelf == false)
    81.             {
    82.                 Image.SetActive(true);
    83.             }
    84.             if (sayı==2 && Red2.activeSelf == false)
    85.             {
    86.                 Image2.SetActive(true);
    87.             }
    88.             if (sayı==3 && Red3.activeSelf == false)
    89.             {
    90.                 Image3.SetActive(true);
    91.             }
    92.             if (sayı == 4 && Red4.activeSelf == false)
    93.             {
    94.                 Image4.SetActive(true);
    95.             }
    96.             if (sayı == 5 && Red5.activeSelf == false)
    97.             {
    98.                 Image5.SetActive(true);
    99.             }
    100.             if (sayı == 6 && Red6.activeSelf == false)
    101.             {
    102.                 Image6.SetActive(true);
    103.             }
    104.             if (sayı == 7 && Red7.activeSelf == false)
    105.             {
    106.                 Image7.SetActive(true);
    107.             }
    108.         }
    109.        
    110.         if (other.gameObject.CompareTag("Respawn"))
    111.         {
    112.             sayı = sayı + 1;
    113.             sayac2 = sayac2 + 1;
    114.             Debug.Log("Sayac2 : " + sayac2);
    115.             Başarılı();
    116.             top = top - 1;
    117.             Debug.Log("Top Kalan : " + top);
    118.  
    119.             if (sayı == 1 && Image.activeSelf == false)
    120.             {
    121.                 Red.SetActive(true);
    122.             }
    123.             if (sayı == 2 && Image2.activeSelf == false)
    124.             {
    125.                 Red2.SetActive(true);
    126.             }
    127.             if (sayı == 3 && Image3.activeSelf == false)
    128.             {
    129.                 Red3.SetActive(true);
    130.             }
    131.             if (sayı == 4 && Image4.activeSelf == false)
    132.             {
    133.                 Red4.SetActive(true);
    134.             }
    135.             if (sayı == 5 && Image5.activeSelf == false)
    136.             {
    137.                 Red5.SetActive(true);
    138.             }
    139.             if (sayı == 6 && Image6.activeSelf == false)
    140.             {
    141.                 Red6.SetActive(true);
    142.             }
    143.             if (sayı == 7 && Image7.activeSelf == false)
    144.             {
    145.                 Red7.SetActive(true);
    146.             }
    147.  
    148.         }
    149.  
    150.     }
    151.    
    152.    
    153. }
    154.  
    155.  
     
  2. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    Your win and lose conditions will never be reached based off the code you've written.

    It's because you're changing your top variable every shot but when you check your win or lose conditions you're checking that top == to whatever you set it to at the start which it will never be (in this case 7), so you will never lose or win.

    Why do you even bother checking if top == 7? surely you should be checking if it's larger than zero before you let the user shoot, otherwise they can shoot as many times as they want.

    EDIT: The reason most people are not going to bother replying to this thread is because

    1. You haven't demonstrated that you have tried to solve it yourself
    2. It's not entirely in English (this being an English speaking forum)
    3. Your variable names are poorly named. (e.g sayac1, sayac2, top, why not give more meaningful names such as Vurmak, Bayan, Denemeler? or in English, Hit, Miss, Attempts).
    4. Something went wrong is very vague, what circumstances does it go right?

    To help in replies another thing you could do is (especially for beginners) comment your code! It will help you as well trying to figure out what is going wrong!
     
    Last edited: Aug 15, 2018
  3. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    I created 7 balls, but I want the system to know that when "count" is 3, it uses the new part and seven "balls".
     
  4. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    I want to users use to seven balls and if three ball basket new scene howewer 5 and more Collider enter respawn restart scene
     
  5. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    brothers ?
     
  6. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    When the basket is 3, go to the new scene but the user must wait for 7 balls to finish
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I tried explaining this in private message, but I'll explain it here again.

    Like @CubicCBridger was saying, what is wrong is when Başarılı() is called, the value of "top" is not going to be 7 at the same time the value of sayac is >= 3 or the value of sayac2 is >= 5. It is not possible for both to be true because by the time sayac and sayac2 are high enough you will have called "top = top - 1;" on lines 75 and 116 several times.

    That means "top" will not be equal to 7, so you should not be checking for "top == 7" on lines 58 and 63. I'm not sure what you're really trying to use "top" for, but checking for its starting value after you have subtracted from it is not going to work.

    Add debugging to Başarılı() to print the value of "top" to the console to see for yourself.

    Code (csharp):
    1. Debug.Log(top.ToString());
     
    Last edited: Aug 16, 2018
  8. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    @takixx we understand what you want your win and lose conditions to be. Both @Joe-Censored and I have explained what you have done wrong. Posting three separate posts re-explaining what you want your win condition and lose condition to be isn't going to change that your implementation of it is not going to work.

    How many balls you start with has nothing to do with your win condition You have already explained, win if 3 in, fail if 5 out. You don't even need to set how many balls the user can throw because the outcome of a throw is either a miss or hit. Its impossible for them to throw more than .

    why do you check if start is 7 EVERYTIME they throw. why do you detract 1 EVERYTIME they throw, why are you not even bothering to read my original post and just re-quote it back at me.

    YES

    if hit >= 3 THEN next level
    else if miss >= THEN 5 fail level
    else continue

    NO

    if hit >= 3 AND some other condition that never passes and doesn't even matter anyway THEN next level
    else if miss >= 5 AND some other condition that never passes and doesn't even matter anyway THEN fail level
    else continue

    no need for his number 7, it doesnt do anything
    4 misses plus 2 hits = 6, the final 7th throw is going to trigger either win or lose condition, why do you check 7

    ALTERNATIVE

    throws += 1
    if (hits < 3 && throws == 7)
    lose
    else if (hits >= 3)
    win
    else
    continue

    You only need two variables not all three for win and lose condition. I've spent far too much energy on this.
     
    Last edited: Aug 17, 2018
  9. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    I wanted to use 7 balls and use it until the last ball BUT
    Now being a 3 ball basket and new stage
    All balls are used until 3 balls are green
    BUT
    3 balls become green and instant new scene
    I want 3 balls to be green then all to the last ball


    THİS İS LİTERALLY
     
  10. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    I'm not sure that I understand you clearly, but I'm guessing that you need something like this:

    Code (CSharp):
    1.     private void Başarılı()
    2.     {
    3.         if (top <1) // used all the balls
    4.         {
    5.           if (sayac >= 3) { //won
    6.             Debug.Log("Yeni Level");
    7.             SceneManager.LoadScene(LevelPassed);
    8.          
    9.         }else
    10.         { // lost
    11.                 Debug.Log("Level Başarısız");
    12.                 SceneManager.LoadScene(YenidenOyna);
    13.         }
    14.     }
    15. }
     
  11. takixx

    takixx

    Joined:
    Apr 10, 2017
    Posts:
    55
    Thank you man !!! My english is a litte bad I know.