using UnityEngine;
using System.Collections;
public class timeController : MonoBehaviour {
public GameObject aniFont1; // holds a sprite sheet - should be a number sheet 0-9
public GameObject aniFont2; // holds a sprite sheet - should be a number sheet 0-9
public GameObject aniFont3; // holds a sprite sheet - should be a number sheet 0-9
public float playTime = 0.0F; // playTime is the current time printed to screen - think of it like current game time
public float continueTimeDown = 0.0F; // used to continue time down from stopped time
public float countDownDelay = 0.0F; // used to delay time during counting
public float countDownAmount = 150F; // amount to delay each time
public bool playTimeEnabled = true; // toggle for playTime
public bool countDownEnabled = true; // toggle for countDown
void aniSprite ( GameObject spriteObject, int columnSize, int rowSize, int colFrameStart, int rowFrameStart, int totalFrames, string type)
{
int index = (int)playTime; // to control frame location, playTime will equal the index count
int font1 = ( index % 10 ); // font1 position
int font2 = ((index - font1) / 10) % 10; // font2 position
int font3 = ((index - font1) / 100) % 10; // font3 position
if ( type == "font1" ) index = font1; // check for which sprite sheet to use - font1
if ( type == "font2" ) index = font2; // check for which sprite sheet to use - font2
if ( type == "font3" ) index = font3; // check for which sprite sheet to use - font3
Vector2 size = new Vector2(1.0F / (float)columnSize, 1.0F / (float)rowSize); // find scale to show on poly
int u = index % columnSize; // u cord separated from v, to find just the column and mod it
int v = index / columnSize; // v finds location on row based on columnSize count
Vector2 offset = new Vector2((float)(u + colFrameStart) * size.x, (float)((1.0 - size.y) - (v + rowFrameStart) * size.y)); // offset uv's
spriteObject.renderer.material.mainTextureOffset = offset; // apply the offset amount to the correct sprite sheet object
spriteObject.renderer.material.mainTextureScale = size; // apply the scale amount to the correct sprite sheet object
}
void Update ()
{
if (aniFont1 != null) aniSprite ( aniFont1, 10, 1, 0, 0, 10, "font1" ); // animated font sprite - type: font1
if (aniFont2 != null) aniSprite ( aniFont2, 10, 1, 0, 0, 10, "font2" ); // animated font sprite - type: font2
if (aniFont3 != null) aniSprite ( aniFont3, 10, 1, 0, 0, 10, "font3" ); // animated font sprite - type: font3
if ( playTimeEnabled && countDownEnabled ) // if countDown enabled, then use this for playTime
{
playTime = countDownDelay - Time.time + countDownAmount + continueTimeDown; // get playTime start
}
if ( playTime <= 0 ) // simple stop for countDown
{
playTimeEnabled = false; // stop timer - playTime
countDownEnabled = false; // stop timer - countDown
}
}
}
using UnityEngine;
using System.Collections;
public class hudController : MonoBehaviour {
public GameObject livesFont;
public GameObject coinFont1; // holds a sprite sheet - should be a number sheet 0-9
public GameObject coinFont2; // holds a sprite sheet - should be a number sheet 0-9
public GameObject coinFont3; // holds a sprite sheet - should be a number sheet 0-9
public GameObject pPlayer;
private playerProperties properties;
private int index = 0;
// public int coin = 0;
// public int lives = 4;
//playerProperties temp;
void aniSprite(GameObject spriteObject, int columnSize, int rowSize, int colFrameStart, int rowFrameStart, int totalFrames, string type, int index)
{
int font1 = (index % 10); // font1 position
int font2 = ((index - font1) / 10) % 10; // font2 position
int font3 = ((index - font1) / 100) % 10; // font3 position
int font4 = (index % 30); // lives
if (type == "font1") index = font1; // check for which sprite sheet to use - font1
if (type == "font2") index = font2; // check for which sprite sheet to use - font2
if (type == "font3") index = font3; // check for which sprite sheet to use - font3
if (type == "font4") index = font4;
Vector2 size = new Vector2(1.0F / (float)columnSize, 1.0F / (float)rowSize); // find scale to show on poly
int u = index % columnSize; // u cord separated from v, to find just the column and mod it
int v = index / columnSize; // v finds location on row based on columnSize count
Vector2 offset = new Vector2((float)(u + colFrameStart) * size.x, (float)((1.0 - size.y) - (v + rowFrameStart) * size.y)); // offset uv's
spriteObject.renderer.material.mainTextureOffset = offset; // apply the offset amount to the correct sprite sheet object
spriteObject.renderer.material.mainTextureScale = size; // apply the scale amount to the correct sprite sheet object
}
void Start()
{
// pPlayer = GameObject.Find("player");
properties = pPlayer.GetComponent<playerProperties>();
}
void Update()
{
//int lives = 4;
if (coinFont1 != null) aniSprite(coinFont1, 10, 1, 0, 0, 10, "font1", properties.coins); // animated font sprite - type: font1
if (coinFont2 != null) aniSprite(coinFont2, 10, 1, 0, 0, 10, "font2", properties.coins); // animated font sprite - type: font2
if (coinFont3 != null) aniSprite(coinFont3, 10, 1, 0, 0, 10, "font3", properties.coins); // animated font sprite - type: font3
if (livesFont != null) aniSprite(livesFont, 10, 1, 0, 0, 10, "font4", properties.lives);
}
}
using UnityEngine;
using System.Collections;
public class itemPickup2701 : MonoBehaviour {
public enum PickupType
{
Grow = 0,
Key = 1,
Coin = 2,
Fireball = 3,
Extralife = 4,
GameTime = 5
}
public PickupType pickupType = PickupType.Grow;
public int pickupValue = 1;
public Transform itemParticle;
public AudioClip soundItemPickup;
public float soundDelay = 0.0f;
public float soundRate = 0.0f;
private GameObject playerGameObject;
private GameObject hudGameObject;
private bool extraLifeEnabled = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections;
[AddComponentMenu("csk0123/Interactive/Pickup Script")]
public class itemPickup2702 : MonoBehaviour {
public enum PickupType
{
Grow = 0,
Key = 1,
Coin = 2,
Fireball = 3,
Extralife = 4,
GameTime = 5
}
public PickupType pickupType = PickupType.Grow;
public int pickupValue = 1;
public Transform itemParticle;
public AudioClip soundItemPickup;
public float soundDelay = 0.0f;
public float soundRate = 0.0f;
private GameObject playerGameObject;
private GameObject hudGameObject;
private bool extraLifeEnabled = false;
// Use this for initialization
void Start()
{
}
void OnTriggerEnter(Collider other) {
}
void ApplyPickup(playerProperties playerStatus)
{
}
IEnumerator PlaySound(AudioClip soundName, float soundDelay)
{
if (!audio.isPlaying && Time.time > soundDelay)
{
soundRate = Time.time + soundDelay;
audio.clip = soundName;
audio.Play();
yield return new WaitForSeconds(audio.clip.length);
}
}
}
using UnityEngine;
using System.Collections;
[AddComponentMenu("csk0123/Interactive/Pickup Script")]
public class itemPickup2703 : MonoBehaviour {
public enum PickupType
{
Grow = 0,
Key = 1,
Coin = 2,
Fireball = 3,
Extralife = 4,
GameTime = 5
}
public PickupType pickupType = PickupType.Grow;
public int pickupValue = 1;
public Transform itemParticle;
public AudioClip soundItemPickup;
public float soundDelay = 0.0f;
public float soundRate = 0.0f;
private GameObject playerGameObject;
private GameObject hudGameObject;
private bool extraLifeEnabled = false;
// Use this for initialization
void Start()
{
playerGameObject = GameObject.FindWithTag("Player");
hudGameObject = GameObject.FindWithTag("hud");
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "collisionBoxBody")
{
}
}
void ApplyPickup(playerProperties playerStatus)
{
hudController hudConnect = (hudController)hudGameObject.GetComponent(typeof(hudController));
switch (pickupType)
{
case PickupType.Grow:
if (playerStatus.MarioState != playerProperties.PlayerState.MarioFire)
{
playerStatus.MarioState = playerProperties.PlayerState.MarioLarge;
playerStatus.changeMario = true;
}
break;
case PickupType.Key:
break;
case PickupType.Coin:
break;
case PickupType.Fireball:
break;
case PickupType.Extralife:
break;
case PickupType.GameTime:
break;
}
}
IEnumerator PlaySound(AudioClip soundName, float soundDelay)
{
if (!audio.isPlaying && Time.time > soundDelay)
{
soundRate = Time.time + soundDelay;
audio.clip = soundName;
audio.Play();
yield return new WaitForSeconds(audio.clip.length);
}
}
}
using UnityEngine;
using System.Collections;
[AddComponentMenu("csk0123/Interactive/Pickup Script")]
public class itemPickup2704 : MonoBehaviour {
public enum PickupType
{
Grow = 0,
Key = 1,
Coin = 2,
Fireball = 3,
Extralife = 4,
GameTime = 5
}
public PickupType pickupType = PickupType.Grow;
public int pickupValue = 1;
public Transform itemParticle;
public AudioClip soundItemPickup;
public float soundDelay = 0.0f;
public float soundRate = 0.0f;
private GameObject playerGameObject;
private GameObject hudGameObject;
private bool extraLifeEnabled = false;
// Use this for initialization
void Start()
{
playerGameObject = GameObject.FindWithTag("Player");
hudGameObject = GameObject.FindWithTag("hud");
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "collisionBoxBody")
{
}
}
void ApplyPickup(playerProperties playerStatus)
{
hudController hudConnect = (hudController)hudGameObject.GetComponent(typeof(hudController));
switch (pickupType)
{
case PickupType.Grow:
if (playerStatus.MarioState != playerProperties.PlayerState.MarioFire)
{
playerStatus.MarioState = playerProperties.PlayerState.MarioLarge;
playerStatus.changeMario = true;
}
break;
case PickupType.Key:
playerStatus.AddKeys(pickupValue);
break;
case PickupType.Coin:
playerStatus.AddCoins(pickupValue);
//hudConnect.coin += pickupValue;
break;
case PickupType.Fireball:
playerStatus.MarioState = playerProperties.PlayerState.MarioFire;
playerStatus.hasFire = true;
playerStatus.changeMario = true;
break;
case PickupType.Extralife:
extraLifeEnabled = true;
break;
case PickupType.GameTime:
// playerStatus.AddTime(pickupValue);
break;
}
}
IEnumerator PlaySound(AudioClip soundName, float soundDelay)
{
if (!audio.isPlaying && Time.time > soundDelay)
{
soundRate = Time.time + soundDelay;
audio.clip = soundName;
audio.Play();
yield return new WaitForSeconds(audio.clip.length);
}
}
}
using UnityEngine;
using System.Collections;
[AddComponentMenu("csk0123/Interactive/Pickup Script")]
public class itemPickup2705 : MonoBehaviour
{
public enum PickupType
{
Grow = 0,
Key = 1,
Coin = 2,
Fireball = 3,
Extralife = 4,
GameTime = 5
}
public PickupType pickupType = PickupType.Grow;
public int pickupValue = 1;
public Transform itemParticle;
public AudioClip soundItemPickup;
public float soundDelay = 0.0f;
public float soundRate = 0.0f;
private GameObject playerGameObject;
private GameObject hudGameObject;
private bool extraLifeEnabled = false;
IEnumerator PlaySound(AudioClip soundName, float soundDelay)
{
// print("test3");
if (!audio.isPlaying && Time.time > soundRate)
{
// print("test4");
soundRate = Time.time + soundDelay;
audio.clip = soundName;
audio.Play();
// print("test5");
yield return new WaitForSeconds(audio.clip.length);
Destroy(gameObject);
// print("test6");
}
// print("test7");
}
// Use this for initialization
void Start()
{
playerGameObject = GameObject.FindWithTag("Player");
hudGameObject = GameObject.FindWithTag("hud");
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "collisionBoxBody")
{
playerProperties pProp = playerGameObject.GetComponent<playerProperties>();
ApplyPickup(pProp);
renderer.enabled = false;
collider.enabled = false;
if (itemParticle)
{
Instantiate(itemParticle, transform.position, transform.rotation);
}
if (soundItemPickup)
{
// print("test");
StartCoroutine(PlaySound(soundItemPickup, 0));
// print("test2");
}
if (extraLifeEnabled)
{
print("extraLife");
pProp.lives += pickupValue;
extraLifeEnabled = false;
}
//Destroy(gameObject);
}
}
void ApplyPickup(playerProperties playerStatus)
{
hudController hudConnect = hudGameObject.GetComponent<hudController>();
switch (pickupType)
{
case PickupType.Grow:
if (playerStatus.MarioState != playerProperties.PlayerState.MarioFire)
{
playerStatus.MarioState = playerProperties.PlayerState.MarioLarge;
playerStatus.changeMario = true;
}
break;
case PickupType.Key:
playerStatus.AddKeys(pickupValue);
break;
case PickupType.Coin:
playerStatus.AddCoins(pickupValue);
//hudConnect.coin += pickupValue;
break;
case PickupType.Fireball:
playerStatus.MarioState = playerProperties.PlayerState.MarioFire;
playerStatus.hasFire = true;
playerStatus.changeMario = true;
break;
case PickupType.Extralife:
//hudConnect.lives += pickupValue;
extraLifeEnabled = true;
break;
case PickupType.GameTime:
// playerStatus.AddTime(pickupValue);
break;
}
}
}
using UnityEngine;
using System.Collections;
public class coinRotate2801 : MonoBehaviour {
int rotateCoinSpeed = 20;
aniSprite aniSpr;
// Use this for initialization
void Start()
{
aniSpr = GetComponent<aniSprite>();
}
// Update is called once per frame
void Update () {
aniSpr.aniPlay(16, 2, 0, 0, 21, rotateCoinSpeed);
}
}