Doubt about c# int [-1,1]

Asked

Viewed 73 times

0

Good person, I made a script where he exchanges objects with setactive in int connected to onclick buttons 1,2,3,4 and so on

I ask help from you to change the int to -1.1 on the onclick buttons the idea would be like this inserir a descrição da imagem aqui

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class trocarobjetos : MonoBehaviour 
{
   private List<GameObject> modelos;
   private int selecaoIndex = 0;

   private void Start()
   {
      modelos= new List<GameObject>();
      foreach(Transform t in transform)
      {
         modelos.Add(t.gameObject);
         t.gameObject.SetActive(false);
      }
      modelos[selecaoIndex].SetActive(true);
   }
   public void SelecionarObjeto(int index)
   {
      if(index ==selecaoIndex)
         return;

      if(index < 0 || index >= modelos.Count)
         return;

      modelos[selecaoIndex].SetActive(false);
      selecaoIndex = index;
      modelos[selecaoIndex].SetActive(true);
   }
}
  • Code does not work ? Error ? The -1 and 1 enters what part ? The tag is not missing unity ?

  • it works perfectly, more with int 1,2,3,4, etcs, wanted to make the change to -1 and 1 in the buttons

  • But what is the -1 and 1 on the buttons ? And what it represents ?

  • For example, there is a way to switch gameobject using setactive with int -1 and 1, previous and next, when I click the inner button it comes back the object that is -1. And the next one is the 1 that is advancing the objects...... I could understand?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.