void Start()
{
if (viewCamera == null)
{
// Find a camera parent
Transform node = transform;
while (node && node.camera == null)
{
node = node.parent;
}
if (node && node.camera != null)
{
viewCamera = node.camera;
}
// See if a tk2dCamera exists
if (viewCamera == null && tk2dCamera.inst)
{
viewCamera = tk2dCamera.inst.mainCamera;
}
// ...otherwise, use the main camera
if (viewCamera == null)
{
viewCamera = Camera.main;
}
}
sprite = GetComponent<tk2dBaseSprite>();
// Further tests for sprite not being null aren't necessary, as the IDs will default to -1 in that case. Testing them will be sufficient
if (sprite)
{
// Change this to use animated sprites if necessary
// Same concept here, lookup Ids and call Play(xxx) instead of .spriteId = xxx
UpdateSpriteIds();
}
if (collider == null)
{
BoxCollider newCollider = gameObject.AddComponent<BoxCollider>();
Vector3 colliderExtents = newCollider.size * 0.5f;
colliderExtents.z = 0.2f;
newCollider.size = colliderExtents * 2.0f;
}
if ((buttonDownSound != null || buttonPressedSound != null || buttonUpSound != null) &&
audio == null)
{
AudioSource audioSource = gameObject.AddComponent<AudioSource>();
audioSource.playOnAwake = false;
}
}