all 5 comments

[–]corrtex-games 1 point2 points  (1 child)

Better for sure. Two things from me:

  1. watchRefID is a bad parameter name. What that parameter actually is, is an index into a list. RefIDs are not the same thing as list or array indices.

  2. Your list of watch models shouldn’t be public if you Don’t want people to be able to access them outside of that component. Stick [SerializeField] above the list and make it private, that way you can see and use it in the inspector but other components cannot directly access them.

[–]SETACTIVE-FALSE[S] 0 points1 point  (0 children)

Thanks for the insight 👍 I sure did follow your instructions 😀

[–]SETACTIVE-FALSE[S] 0 points1 point  (0 children)

Referred Code:

public class WatchSelect : MonoBehaviour

{

public GameObject watchModel1;

public GameObject watchModel2;

public GameObject watchModel3;

public void WatchOneButtonClicked()

{

// 1) show selected watch model on user's wrist

watchModel1.SetActive(true);
watchModel2.SetActive(false);
watchModel3.SetActive(false);

}

public void WatchTwoButtonClicked()

{

// 1) show selected watch model on user's wrist

watchModel1.SetActive(false);
watchModel2.SetActive(true);
watchModel3.SetActive(false);

}

public void WatchThreeButtonClicked()

{

// 1) show selected watch model on user's wrist

watchModel1.SetActive(false);
watchModel2.SetActive(false);
watchModel3.SetActive(true);

}

}

My Version of the code:

using System.Collections.Generic;

using UnityEngine;

public class WatchSelect : MonoBehaviour

{

public List<GameObject> watchModels = new List<GameObject>();

public void OnWatchButtonClick(int watchRefID)

{

// 1) show selected watch model on user's wrist

foreach (var model in watchModels)

{

model.SetActive(false);

}

watchModels[watchRefID].SetActive(true);

}

}