Question by
d schotting · Jul 01, 2016 at 08:52 AM ·
canvasimagesduplicate
Duplicate image instances on canvas
I made a series of 4 images that have a 2D position that follows a 3D position (by FollowWorldPosition.cs script) in the world. They behave as expected, except for the fact that there are duplicates in different positions.
I expect that i need to use a different transform method or am creating instances unknowingly. Please help me get rid of the duplicates.
This is the script on the images:
using UnityEngine; using System.Collections;
public class PositionHotspotIcon : MonoBehaviour {
public float hotspotId;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var cameraRef = GameObject.Find("Main Camera");
var componentRef = cameraRef.GetComponent<WorldToScreenPoint>();
float xRef = 0;
float yRef = 0;
if(hotspotId == 1)
{
xRef = componentRef.xRef;
yRef = componentRef.yRef;
print("hotspot ID = 1");
}
else if (hotspotId == 2)
{
xRef = componentRef.xRef2;
yRef = componentRef.yRef2;
print("hotspot ID = 2");
}
else if(hotspotId == 3)
{
xRef = componentRef.xRef3;
yRef = componentRef.yRef3;
print("hotspot ID = 3");
}
else if(hotspotId == 4)
{
xRef = componentRef.xRef4;
yRef = componentRef.yRef4;
print("hotspot ID = 4");
}
else
{
xRef = 0;
yRef = 0;
print("hotspot ID = N/A");
}
//transform.position = new Vector2(xRef,yRef);
RectTransform rTrans = (RectTransform)transform.GetComponent<RectTransform>();
}
}
Comment