I am trying to adapt Unity DraggingAndDroppingMultiple project so that when you click a button it randomly selects an image from an array of images and updates the texture on a cube. The aim is to place these photo objects in AR.
I am using Unity 2019.1.10f1 and am getting some errors.
I have the following in SpawnPhoto.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnPhoto : MonoBehaviour
{
public GameObject photoPrefab;
public static Sprite[] photoLibrary;
public string photoName;
int arrayIdx = Random.Range (0, photoLibrary.Length);
Sprite photo = photoLibrary[arrayIdx];
photoName = photo.name;
}
and in Placement WithMultipleDraggingDroppingController.cs
void Awake()
{
arRaycastManager = GetComponent<ARRaycastManager>();
dismissButton.onClick.AddListener(Dismiss);
photoID = GetComponent<SpawnPhoto>().photoName;
if (redButton != null && greenButton != null && blueButton != null)
{
redButton.onClick.AddListener(() => ChangePrefabSelection("ARRed"));
greenButton.onClick.AddListener(() => ChangePrefabSelection("ARGreen"));
blueButton.onClick.AddListener(() => ChangePrefabSelection("ARBlue"));
yellowButton.onClick.AddListener(() => SelectRandomPhoto($"{photoID}"));
}
}
private void SelectRandomPhoto(string name)
{
GameObject loadedGameObject = Resources.Load<SpawnPhoto>($"Prefabs/{name}");
if (loadedGameObject != null)
{
PlacedPrefab = loadedGameObject;
Debug.Log($"Game object with name {name} was loaded");
}
else
{
Debug.Log($"Unable to find a game object with name {name}");
}
}
private void ChangePrefabSelection(string name)
{
GameObject loadedGameObject = Resources.Load<GameObject>($"Prefabs/{name}");
if(loadedGameObject != null)
{
PlacedPrefab = loadedGameObject;
Debug.Log($"Game object with name {name} was loaded");
}
else
when saving the console shows an issue with photoName variable in the first block above.
saying that Invalid Token '=' in class, struct or interface member declaration.