Post by raymond on Sept 20, 2016 3:34:37 GMT
I am using Floating or Overlay Text that Displays Points on Items collected or Enemies destroyed directly on the Game Objects on the screen.
I am currently using Instantiate and Destroy on them because I do not know how to use Core Gamekit to spawn and despawn GUI Items.
My code with the Instantiate is below. I am going to paste all the code so it makes more sense to you. You can tell all my failed attempts in grey.
I will post the code that has the Destroy Code in it following trying to figure this out.
Thanks For any help you can give.
----------------------------------------------------------------------------------------------------------------------------------------------------
public class FloatingTextController: MonoBehaviour {
private static FloatingText popupText;
private static GameObject canvas;
FloatingText myFloatingText;
public static void Intialize()
{
canvas = GameObject.Find ("CanvasPopup"); // set as tag in future
popupText = Resources.Load<FloatingText>("TextPrefab/PopUpTextParent");
}
public static void CreateFloatingText(string text, Transform transform)
{
print ("RUN FLOATING TEXT CONTROLLER FUNCTION");
Vector2 screenPosition = Camera.main.WorldToScreenPoint (transform.position);
FloatingText instance = Instantiate (popupText);
//FloatingText instance = PoolBoss.SpawnInPool(popupText);
//FloatingText instance = PoolBoss.SpawnInPool(popupText, screenPosition).FloatingText as FloatingText;
// newItem = DarkTonic.CoreGameKit.PoolBoss.SpawnInPool (spawnPlatform.transform, spawnPlatform.transform.position, spawnPlatform.transform.rotation);
//Vector2 screenPosition = Camera.main.WorldToScreenPoint (new Vector2(transform.position.x,transform.position.y));
// new Vector2(transform.position.x - 45, 0);
instance.transform.SetParent (canvas.transform, false);
instance.transform.position = screenPosition;
instance.SetText(text);
}
}
I am currently using Instantiate and Destroy on them because I do not know how to use Core Gamekit to spawn and despawn GUI Items.
My code with the Instantiate is below. I am going to paste all the code so it makes more sense to you. You can tell all my failed attempts in grey.
I will post the code that has the Destroy Code in it following trying to figure this out.
Thanks For any help you can give.
----------------------------------------------------------------------------------------------------------------------------------------------------
public class FloatingTextController: MonoBehaviour {
private static FloatingText popupText;
private static GameObject canvas;
FloatingText myFloatingText;
public static void Intialize()
{
canvas = GameObject.Find ("CanvasPopup"); // set as tag in future
popupText = Resources.Load<FloatingText>("TextPrefab/PopUpTextParent");
}
public static void CreateFloatingText(string text, Transform transform)
{
print ("RUN FLOATING TEXT CONTROLLER FUNCTION");
Vector2 screenPosition = Camera.main.WorldToScreenPoint (transform.position);
FloatingText instance = Instantiate (popupText);
//FloatingText instance = PoolBoss.SpawnInPool(popupText);
//FloatingText instance = PoolBoss.SpawnInPool(popupText, screenPosition).FloatingText as FloatingText;
// newItem = DarkTonic.CoreGameKit.PoolBoss.SpawnInPool (spawnPlatform.transform, spawnPlatform.transform.position, spawnPlatform.transform.rotation);
//Vector2 screenPosition = Camera.main.WorldToScreenPoint (new Vector2(transform.position.x,transform.position.y));
// new Vector2(transform.position.x - 45, 0);
instance.transform.SetParent (canvas.transform, false);
instance.transform.position = screenPosition;
instance.SetText(text);
}
}