I have the following situation. I am trying to place an image from a C# script in Unity 3d, when reading a pattern with Vuforia . What is happening to me is that from the moment I create the public variable for the image, it tells me that it is ambiguous .
In that same scene I have a text that I insert from a database, inside a UI element type text and the image must be above that text. With the text I have no problem. The problem is appearing to me with the image. if I remove UnityEngine.UI the conflict with the image is removed but I can't use the text UI. Now if I remove Vuforia there if I don't have the conflict with the image but reading the pattern doesn't work for me. Below I leave the code to see if you can help me to be able to work with the two elements without sending me the ambiguous message .
Thanks.
Mistake:
error CS0104:
Image' is an ambiguous reference between
Vuforia.Image' and `UnityEngine.UI.Image'
Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using UnityEngine.UI;
using Mono.Data.Sqlite;
using System.Data;
using System;
using System.IO;
public class reproduccionAudio : MonoBehaviour, ITrackableEventHandler
{
private TrackableBehaviour mTrackableBehaviour;
//public AudioClip otherClip;
private AudioSource audio;
private AudioSource[] allAudioSources;
public Text textoLibro;
private SqliteConnection dbconn;
private SqliteCommand dbcmd;
private SqliteDataReader reader;
private string conn;
private string namedb = "usuario.bytes";
public int nParrafo;
public Image imgEscena;
void Start()
{
//Traemos el valor del GameObject y lo acipnamos el audioSouce
audio = GetComponent<AudioSource>();
imgEscena = GameObject.Find ("Escenas").GetComponents<Image> ();
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus){
/*
if(audio.isPlaying ){
audio.Stop ();
}*/
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) {
allAudioSources = FindObjectsOfType (typeof(AudioSource)) as AudioSource[];
foreach (AudioSource audioS in allAudioSources){
audioS.Stop ();
}
textoLibro.text = "";
if (!audio.isPlaying) {
audio.Play ();
}
//Colocamos el texto de la naración en pantalla.
getOpenDb();
string sqlQuery = "Select * From textoLibros WHERE nParrafo = "+ nParrafo +" AND idusuario = 0";
dbcmd = dbconn.CreateCommand();
dbcmd.CommandText = sqlQuery;
reader = dbcmd.ExecuteReader ();
while(reader.Read()){
string names = reader.GetString (2);
textoLibro.text = names;
//Debug.Log (" Nombre"+ names);
}
imgEscena.sprite = Resources.Load<Sprite> ("escenas-RA/EscenaRa-01");
getCloseDb ();
}
}
//
// Creamos la conexion con la bd SQlite
//
public void getOpenDb(){
if (Application.platform != RuntimePlatform.Android) {
conn = Application.dataPath + "/StreamingAssets/" + namedb;
if(!File.Exists(conn)){
File.Create (conn);
}
} else {
conn = Application.persistentDataPath + "/" + namedb;
if (!File.Exists(conn))
{
// if it doesn't ->
// open StreamingAssets directory and load the db ->
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + namedb); // this is the path to your StreamingAssets in android
while (!loadDB.isDone) { } // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
// then save to Application.persistentDataPath
File.WriteAllBytes(conn, loadDB.bytes);
}
}
dbconn = new SqliteConnection ("URI=file:" + conn);
dbconn.Open ();
}
//
//Cerramos la conexión Sqlite
//
public void getCloseDb(){
reader.Close ();
reader = null;
dbcmd.Dispose ();
dbcmd = null;
dbconn.Close ();
dbconn = null;
}
}
Both libraries add the Image class, which C# doesn't know which Image of the 2 you mean.
In this case you will have to include the namespace in the declaration: