#Synchronization Help!

1 messages · Page 1 of 1 (latest)

swift ridge
#

Help! When I change weapons, they change for others (synchronization problem)
code: using UnityEngine;

public class ToggleObjects : MonoBehaviour
{
public GameObject object1;
public GameObject object2;
public GameObject object3;

void Update()
{
    if (Input.GetKeyDown(KeyCode.Alpha1))
    {
        ToggleVisibility(object1, object2, object3);
    }
    else if (Input.GetKeyDown(KeyCode.Alpha2))
    {
        ToggleVisibility(object2, object1, object3);
    }
    else if (Input.GetKeyDown(KeyCode.Alpha3))
    {
        ToggleVisibility(object3, object1, object2);
    }
}

void ToggleVisibility(GameObject active, GameObject inactive1, GameObject inactive2)
{
    active.SetActive(true);
    inactive1.SetActive(false);
    inactive2.SetActive(false);
}

}

ivory apex
swift ridge
#

How to fix it?

ivory apex
#

See PickupsDropsChilds example in latest Asset Store release for how to do that correctly.

swift ridge