9. 基于Unity的VR艺术画廊

阅读 26

2024-08-22

9. 基于Unity的VR艺术画廊

using UnityEngine;

public class VRArtGallery : MonoBehaviour
{
    public GameObject[] artPieces;
    private int currentArtIndex = 0;

    void Start()
    {
        if (artPieces.Length > 0)
        {
            LoadArtPiece(0);
        }
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            PreviousArtPiece();
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            NextArtPiece();
        }
    }

    void LoadArtPiece(int index)
    {
        for (int i = 0; i < artPieces.Length; i++)
        {
            artPieces[i].SetActive(i == index);
        }
    }

    void PreviousArtPiece()
    {
        currentArtIndex = (currentArtIndex - 1 + artPieces.Length) % artPieces.Length;
        LoadArtPiece(currentArtIndex);
    }

    void NextArtPiece()
    {
        currentArtIndex = (currentArtIndex + 1) % artPieces.Length;
        LoadArtPiece(currentArtIndex);
    }
}    void LoadArtPiece(int index)
    {
        for (int i = 0; i < artPieces.Length; i++)
        {
            artPieces[i].SetActive(i == index);
        }
    }

    void PreviousArtPiece()
    {
        currentArtIndex = (currentArtIndex - 1 + artPieces.Length) % artPieces.Length;
        LoadArtPiece(currentArtIndex);
    }

    void NextArtPiece()
    {
        currentArtIndex = (currentArtIndex + 1) % artPieces.Length;
        LoadArtPiece(currentArtIndex);
    }
}    void LoadArtPiece(int index)
    {
        for (int i = 0; i < artPieces.Length; i++)
        {
            artPieces[i].SetActive(i == index);
        }
    }

    void PreviousArtPiece()
    {
        currentArtIndex = (currentArtIndex - 1 + artPieces.Length) % artPieces.Length;
        LoadArtPiece(currentArtIndex);
    }

    void NextArtPiece()
    {
        currentArtIndex = (currentArtIndex + 1) % artPieces.Length;
        LoadArtPiece(currentArtIndex);
    }
}

精彩评论(0)

0 0 举报