Skip to content

Instantly share code, notes, and snippets.

@dtb49
Last active December 1, 2016 15:31
Show Gist options
  • Save dtb49/4f6793720cdbe4b15389f2638d0fb25f to your computer and use it in GitHub Desktop.
Save dtb49/4f6793720cdbe4b15389f2638d0fb25f to your computer and use it in GitHub Desktop.
3D endless scroller game
using UnityEngine;
using System.Collections;
public class AudioManager : MonoBehaviour {
AudioSource randAudio;
public AudioSource[] audios;
public AudioSource dying;
//AudioSource errorAudio;
void Start() {
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
//audios = GetComponents<AudioSource>();
randAudio = audios [Random.Range (0, audios.Length)];
randAudio.volume = 1.0f;
randAudio.Play ();
}
// Update is called once per frame
void Update () {
if (!randAudio.isPlaying)
{
randAudio = audios [Random.Range (0, audios.Length)];
randAudio.Play ();
}
}
private void GameStart()
{
randAudio.volume = 0.5f;
dying.Stop ();
//randAudio.Stop ();
//audios = GetComponents<AudioSource>();
//randAudio = audios [Random.Range (0, audios.Length)];
//randAudio.Play ();
}
private void GameOver()
{
randAudio.volume = 0.2f;
//randAudio.Stop ();
dying.Play ();
//dying.SetScheduledEndTime (5);
}
}
using UnityEngine;
using System.Collections;
public class CoinCollect : MonoBehaviour {
public Vector3 rotationVelocity, offset;
public float recycleOffset, spawnChance;
public AudioSource collected;
private int coin = 0;
// Use this for initialization
void Start () {
GameEventManager.GameOver += GameOver;
gameObject.SetActive(false);
}
// Update is called once per frame
void Update () {
if(transform.localPosition.x + recycleOffset < PlayerController.distanceTraveled)
{
gameObject.SetActive(false);
return;
}
transform.Rotate (rotationVelocity * Time.deltaTime);
}
void OnTriggerEnter(Collider info)
{
if (info.tag == "Player")
{
//Debug.Log("Coin");
collected.Play();
coin++;
GUIManager.Coins(coin);
gameObject.SetActive(false);
}
}
public void SpawnIfAvailable (Vector3 position) {
if (gameObject.activeSelf || spawnChance <= Random.Range (0f, 100f)) {
return;
} else {
transform.localPosition = position + offset;
gameObject.SetActive (true);
}
}
private void GameOver () {
gameObject.SetActive(false);
coin = 0;
}
}
using UnityEngine;
using System.Collections;
public class Entity : MonoBehaviour {
public float health;
public GameObject ragdoll;
public void TakeDamage(float damage)
{
health -= damage;
if (health <= 0)
{
Die ();
}
}
public void Die()
{
//Debug.Log("DIE");
//cam.SetTarget (ragdoll.transform);
Ragdoll r = (Instantiate (ragdoll, transform.position, transform.rotation) as GameObject).GetComponent<Ragdoll>();
//Destroy (this.gameObject);
//renderer.enabled = false;
GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;
//GameManager.SpawnPlayer ();
GameEventManager.TriggerGameOver ();
}
}
public static class GameEventManager {
public delegate void GameEvent();
public static event GameEvent GameStart, GameOver;
public static void TriggerGameStart(){
if(GameStart != null){
GameStart();
}
}
public static void TriggerGameOver(){
if(GameOver != null){
GameOver();
}
}
}
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public GameObject player;
private GamerCamera cam;
// Use this for initialization
void Start () {
cam = GetComponent<GamerCamera> ();
SpawnPlayer ();
}
public void SpawnPlayer()
{
cam.SetTarget((Instantiate (player, Vector3.zero, Quaternion.identity) as GameObject).transform);
}
}
using UnityEngine;
using System.Collections;
public class GamerCamera : MonoBehaviour {
private Transform target;
private float trackSpeed = 10;
public void SetTarget(Transform t)
{
target = t;
}
void LateUpdate()
{
if (target)
{
float x = IncrementTowards(transform.position.x, target.position.x,trackSpeed);
float y = IncrementTowards(transform.position.y, target.position.y,trackSpeed);
//float z = IncrementTowards(transform.position.z, target.position.z,trackSpeed);
transform.position = new Vector3(x,y,transform.position.z);
}
}
//Increase n towards target by a
private float IncrementTowards(float n, float target, float a)
{
if (n == target)
{
return n;
}
else
{
float dir = Mathf.Sign (target - n); //does n need to be increased or decreased to reach target
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign (target-n))? n: target; //if n has passed target return targeet otherwise return n
}
}
}
<?php
//connect to the database
include 'mysqli_connect.php';
//get the input
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$currentscore = $_REQUEST['highscore'];
$u = mysqli_real_escape_string($dbc, trim($username));
//query the database
$query = "SELECT * FROM conquest_users WHERE email='$u' AND password=SHA1('$password')";
//echo $query;
//get the results
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_assoc ($result);
$highscore = $row['highscore'];
if($currentscore > $highscore)
{
$update = "UPDATE conquest_users SET highscore='$currentscore' WHERE email='$u' and password=SHA1('$password')";
$result_update = mysqli_query($dbc, $update);
//$update_row = mysqli_fetch_assoc($result_update);
//echo $update_row['highscore'];
$query = "SELECT * FROM conquest_users WHERE email='$u' AND password=SHA1('$password')";
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_assoc ($result);
echo $row['highscore'];
}else{
//test the results
if(mysqli_num_rows($result) == 1)
{
echo $highscore;
//echo $currentscore;
}else
echo "wrong";
}
?>
using UnityEngine;
using System.Collections;
public class GUIManager : MonoBehaviour {
public GUIText gameOverText, instructionsText, runnerText, distanceText, cointText;
public GUIText logoutText, highscoreText, arrowText, sprintText;
private int zero = 0;
private static GUIManager instance;
string getscoreurl = "http://nerdislander.com/apps/conquestking/getscore.php";
string updatescoreurl = "http://nerdislander.com/apps/conquestking/updatescore.php";
void Start () {
instance = this;
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
gameOverText.enabled = false;
highscoreText.enabled = false;
}
void Update () {
if(Input.GetButtonDown("Jump")){
GameEventManager.TriggerGameStart();
}
if (Input.GetButtonDown ("Logout")) {
Application.LoadLevel("login");
}
if (Input.GetButtonDown ("Highscore")) {
Application.LoadLevel("highscore");
}
}
private void GameStart () {
gameOverText.enabled = false;
instructionsText.enabled = false;
arrowText.enabled = false;
sprintText.enabled = false;
runnerText.enabled = false;
logoutText.enabled = false;
highscoreText.enabled = false;
enabled = false;
instance.cointText.text = zero.ToString ();
}
private void GameOver () {
gameOverText.enabled = true;
instructionsText.enabled = true;
arrowText.enabled = true;
sprintText.enabled = true;
highscoreText.enabled = true;
logoutText.enabled = true;
enabled = true;
int score = (int)PlayerController.distanceTraveled;
StartCoroutine (getHighScore (LoginMenu.userName, LoginMenu.passWord, score));
}
public static void SetDistance(float distance)
{
instance.distanceText.text = distance.ToString("f0");
}
public static void Coins(int coin)
{
instance.cointText.text = coin.ToString ("f0");
}
IEnumerator getHighScore(string userNamez, string passWordz, int currentscore)
{
string getscore_url = getscoreurl + "?username=" + userNamez + "&password=" + passWordz + "&highscore=" + currentscore;
WWW scoreReader = new WWW (getscore_url);
yield return scoreReader;
if (scoreReader.error != null) {
highscoreText.text = "Could not locate page";
} else {
string dbscore = scoreReader.text;
highscoreText.text = "Highscore: " + dbscore;
}
}
}
using UnityEngine;
using System.Collections;
public class Highscore : MonoBehaviour {
string highscore_url = "http://nerdislander.com/apps/conquestking/highscore.php";
string[] playerData;
public GUIText score1, score2, score3, score4, score5;
void Start()
{
//Debug.Log ("Starting...");
StartCoroutine(getHighScores ());
//Debug.Log ("Finished...");
}
void Update () {
if (Input.GetButtonDown ("Jump")) {
Application.LoadLevel("Scene3");
}
}
IEnumerator getHighScores()
{
WWW highReader = new WWW (highscore_url);
//Debug.Log ("Reader waiting...");
yield return highReader;
if (highReader.error != null) {
//Debug.Log (highReader.error);
;
} else {
//Debug.Log("Reader returned");
string highscores = highReader.text;
//Debug.Log (highscores);
string[] playerEntries = highscores.Split('\n');
foreach(string entry in playerEntries)
{
playerData = entry.Split( '-' );
string playerName = playerData[ 0 ];
string playerScore = playerData[ 1 ];
//Debug.Log(playerName);
//Debug.Log (playerScore);
//Debug.Log (playerData[2]);
}
score1.text+=" "+ playerData[0] +" "+ playerData[1];
score2.text+=" "+ playerData[2] +" "+ playerData[3];
score3.text+=" "+ playerData[4] +" "+ playerData[5];
score4.text+=" "+ playerData[6] +" "+ playerData[7];
score5.text+=" "+ playerData[8] +" "+ playerData[9];
}
}
}
<?php
//connect to the database
include 'mysqli_connect.php';
$query = "SELECT `email`, `highscore` FROM `conquest_users` ORDER BY highscore DESC LIMIT 5";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo $row['email']."-".$row['highscore']."-";
}
?>
<?php
//connect to the database
include 'mysqli_connect.php';
//get the input
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$u = mysqli_real_escape_string($dbc, trim($username));
//query the database
$query = "SELECT * FROM conquest_users WHERE email='$u' AND password=SHA1('$password')";
//echo $query;
//get the results
$result = mysqli_query($dbc, $query);
//test the results
if(mysqli_num_rows($result) == 1)
echo "right";
else
echo "wrong";
?>
using UnityEngine;
using System.Collections;
public class LoginMenu : MonoBehaviour {
string loginURL = "http://nerdislander.com/apps/conquestking/login.php";
string registerURL = "http://nerdislander.com/apps/conquestking/register.php";
string getscoreurl = "http://nerdislander.com/apps/conquestking/getscore.php";
public static string userName = "";
public static string passWord = "";
string problem = "";
void OnGUI()
{
GUI.Window (0, new Rect (Screen.width/4, Screen.height/4, Screen.width/2, Screen.height/2), LoginWindow, "Login");
}
//create GUI
void LoginWindow(int windowID)
{
//GUI.Label (new Rect (140, 40, 130, 100), " Username ");
GUI.Label (new Rect (210, 40, 130, 100), " Username ");
userName = GUI.TextField (new Rect (65, 60, 375, 30), userName);
GUI.Label (new Rect (210, 92, 130, 100), " Password ");
passWord = GUI.PasswordField (new Rect (65, 112, 375, 30), passWord, "*"[0]);
if (GUI.Button (new Rect (65, 160, 175, 50), "Login"))
StartCoroutine (handleLogin (userName, passWord));
//StartCoroutine (getHighScore (userName, passWord, 10));
if (GUI.Button (new Rect (265, 160, 175, 50), "Register"))
StartCoroutine (handleRegister (userName, passWord));
GUI.Label (new Rect (85, 222, 250, 100), problem);
}
//if login button is pressed
IEnumerator handleLogin(string userNamez, string passWordz)
{
problem = "Checking username and password. . .";
string login_URL = loginURL + "?username=" + userNamez + "&password=" + passWordz;
WWW loginReader = new WWW (login_URL);
yield return loginReader;
if (loginReader.error != null) {
problem = "Could not locate page";
} else {
if(loginReader.text == "right")
{
problem = "Logged in";
//play the game
Application.LoadLevel("Scene3");
}else{
problem = "Invalid username/password.";
}
}
}
//if register button is pressed
IEnumerator handleRegister(string userNamez, string passWordz)
{
problem = "Checking username and password. . .";
string register_URL = registerURL + "?username=" + userNamez + "&password=" + passWordz;
WWW registerReader = new WWW (register_URL);
yield return registerReader;
if (registerReader.error != null) {
problem = "Could not locate page";
} else {
if(registerReader.text == "registered")
{
problem = "Registered!";
}else{
problem = "invalid user/pass";
}
}
}
/*IEnumerator getHighScore(string userNamez, string passWordz, float currentscore)
{
string getscore_url = getscoreurl + "?username=" + userNamez + "&password=" + passWordz;
WWW scoreReader = new WWW (getscore_url);
yield return scoreReader;
if (scoreReader.error != null) {
problem = "Could not locate page";
} else {
//string dbscore = scoreReader.text;
problem = scoreReader.text;
//float highscore = int.Parse(dbscore);
//if(currentscore > highscore)
//{
// problem += highscore;
//updateHighScore(userNamez,passWordz,currentscore);
//}else{
//if not better score do nothing
// ;
//}
}
}*/
}
using UnityEngine;
using System.Collections.Generic;
public class PlatformManager : MonoBehaviour {
public Transform prefab;
public int numberOfObjects;
public float recycleOffset;
public Vector3 startPosition;
public Vector3 minSize, maxSize, minGap, maxGap;
public float minY, maxY;
public Sawblade sawblade;
public CoinCollect coin;
private Vector3 nextPosition;
private Queue<Transform> objectQueue;
void Start () {
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
objectQueue = new Queue<Transform>(numberOfObjects);
for (int i = 0; i < numberOfObjects; i++) {
//prefab.renderer.material.color = new Color(Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
objectQueue.Enqueue((Transform)Instantiate(
prefab, new Vector3(0f, 0f, -100f), Quaternion.identity));
}
enabled = false;
}
void Update () {
if(objectQueue.Peek().localPosition.x + recycleOffset < PlayerController.distanceTraveled){
Recycle();
}
}
private void Recycle () {
Vector3 scale = new Vector3(
Random.Range(minSize.x, maxSize.x),
Random.Range(minSize.y, maxSize.y),
Random.Range(minSize.z, maxSize.z));
Vector3 position = nextPosition;
position.x += scale.x * 0.5f;
position.y += scale.y * 0.5f;
sawblade.SpawnIfAvailable (position);
coin.SpawnIfAvailable (position);
Transform o = objectQueue.Dequeue();
o.localScale = scale;
o.localPosition = position;
objectQueue.Enqueue(o);
nextPosition += new Vector3(
Random.Range(minGap.x, maxGap.x) + scale.x,
Random.Range(minGap.y, maxGap.y),
Random.Range(minGap.z, maxGap.z));
if(nextPosition.y < minY){
nextPosition.y = minY + maxGap.y;
}
else if(nextPosition.y > maxY){
nextPosition.y = maxY - maxGap.y;
}
}
private void GameStart () {
nextPosition = startPosition;
for(int i = 0; i < numberOfObjects; i++){
Recycle();
}
enabled = true;
}
private void GameOver () {
enabled = false;
}
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerPhysics))]
public class PlayerController : Entity {
public static float distanceTraveled;
public float gameOverY = -6;
public static Vector3 startPosition;
//Player handling
public float gravity = 20;
public float walkSpeed = 8;
public float runSpeed = 12;
public float acceleration = 12;
public float jumpHeight = 12;
private float currentSpeed;
private float targetSpeed;
private Vector2 amountToMove;
private PlayerPhysics playerPhysics;
private bool canDoubleJump;
AudioSource dying;
//private Animator animator;
// Use this for initialization
void Start () {
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
startPosition = transform.localPosition;
GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;
rigidbody.isKinematic = true;
enabled = false;
playerPhysics = GetComponent<PlayerPhysics> ();
dying = GetComponent<AudioSource>();
animation.wrapMode = WrapMode.Loop;
animation ["Slide"].wrapMode = WrapMode.Once;
animation["Jump"].wrapMode = WrapMode.Once;
animation["Death"].wrapMode = WrapMode.Once;
animation ["Slide"].layer = 1;
animation ["Jump"].layer = 1;
animation ["Death"].layer = 2;
animation.Stop ();
}
// Update is called once per frame
void Update () {
//keep track of how far the player has moved
distanceTraveled = transform.localPosition.x;
GUIManager.SetDistance (distanceTraveled);
if(transform.localPosition.y < gameOverY){
//dying.Play();
GameEventManager.TriggerGameOver();
}
if (playerPhysics.movementStopped)
{
targetSpeed = 0;
currentSpeed = 0;
}
//animator.SetFloat ("Speed", currentSpeed);
//input
float speed = (Input.GetButton("Run"))?runSpeed:walkSpeed;
targetSpeed = Input.GetAxisRaw ("Horizontal") * speed;
currentSpeed = IncrementTowards (currentSpeed, targetSpeed, acceleration);
animation.Play ("Walk");
animation["Walk"].speed = currentSpeed;
animation.CrossFade("Walk");
if (Mathf.Abs(Input.GetAxis("Horizontal")) <= 0.1 || !playerPhysics.grounded)
{
animation.Play("Idle");
animation.CrossFade("Idle");
}
if (playerPhysics.grounded)
{
canDoubleJump = true;
amountToMove.y = 0;
//Jump
if(Input.GetButtonDown("Jump"))
{
amountToMove.y = jumpHeight;
animation.CrossFade("Jump");
}
}
if(canDoubleJump && !playerPhysics.grounded)
{
if(Input.GetButtonDown("Jump"))
{
amountToMove.y = jumpHeight;
canDoubleJump = false;
animation.CrossFade("Jump");
}
}
amountToMove.x = currentSpeed;
amountToMove.y -= gravity * Time.deltaTime;
playerPhysics.Move (amountToMove * Time.deltaTime);
//Slide
if (Input.GetButtonDown ("Slide"))
{
animation.CrossFade("Slide");
}
}
//Increase n towards target by a
private float IncrementTowards(float n, float target, float a)
{
if (n == target)
{
return n;
}
else
{
float dir = Mathf.Sign (target - n); //does n need to be increased or decreased to reach target
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign (target-n))? n: target; //if n has passed target return targeet otherwise return n
}
}
private void GameStart () {
distanceTraveled = 0f;
GUIManager.SetDistance (distanceTraveled);
transform.localPosition = startPosition;
GetComponentInChildren<SkinnedMeshRenderer>().enabled = true;
rigidbody.isKinematic = false;
enabled = true;
}
private void GameOver () {
GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;
rigidbody.isKinematic = true;
enabled = false;
//dying.Play();
//dying.SetScheduledEndTime (3);
//yield return new WaitForSeconds(3);
//dying.Stop();
}
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider))]
public class PlayerPhysics : MonoBehaviour {
public LayerMask collisionMask;
private BoxCollider collider;
private Vector3 s;
private Vector3 c;
private Vector3 originalSize;
private Vector3 originalCentre;
private float colliderScale;
private float skin = .005f;
private int collisionDivisionX = 3;
private int collisionDivisionY = 10;
[HideInInspector]
public bool grounded;
[HideInInspector]
public bool movementStopped;
Ray ray;
RaycastHit hit;
void Start()
{
collider = GetComponent<BoxCollider> ();
colliderScale = transform.localScale.x;
originalSize = collider.size;
originalCentre = collider.center;
s = collider.size;
c = collider.center;
}
public void Move(Vector2 moveAmount)
{
float deltaY = moveAmount.y;
float deltaX = moveAmount.x;
Vector2 p = transform.position;
//Check collisions above and bellow
grounded = false;
for (int i = 0; i<collisionDivisionX; i++)
{
float dir = Mathf.Sign(deltaY);
float x = (p.x + c.x - s.x/2) + s.x/(collisionDivisionX - 1) * i;
float y = p.y + c.y + s.y/2 * dir;
ray = new Ray(new Vector2(x,y), new Vector2(0, dir));
Debug.DrawRay(ray.origin, ray.direction);
if(Physics.Raycast(ray, out hit, Mathf.Abs (deltaY) + skin, collisionMask))
{
//Get distance between player and ground
float dst = Vector3.Distance (ray.origin, hit.point);
//Stop player's downwards movement after coming skin width of a collider
if(dst > skin)
{
deltaY = dst * dir - skin * dir;
}else{
deltaY = 0;
}
grounded = true;
break;
}
}
//Check collisions left and right
movementStopped = false;
for (int i = 0; i<collisionDivisionY; i++)
{
float dir = Mathf.Sign(deltaX);
float x = p.x + c.x + s.x/2 * dir;
float y = p.y + c.y - s.y/2 + s.y/(collisionDivisionY - 1) * i;
ray = new Ray(new Vector2(x,y), new Vector2(dir,0));
Debug.DrawRay(ray.origin, ray.direction);
if(Physics.Raycast(ray, out hit, Mathf.Abs (deltaX) + skin, collisionMask))
{
//Get distance between player and ground
float dst = Vector3.Distance (ray.origin, hit.point);
//Stop player's downwards movement after coming skin width of a collider
if(dst > skin)
{
deltaX = dst * dir - skin * dir;
}else{
deltaX = 0;
}
movementStopped = true;
break;
}
}
if (!grounded && !movementStopped)
{
Vector3 playerDir = new Vector3 (deltaX, deltaY);
Vector3 o = new Vector3 (p.x + c.x + s.x / 2 * Mathf.Sign (deltaX), p.y + c.y + s.y / 2 * Mathf.Sign (deltaY));
ray = new Ray (o, playerDir.normalized);
if (Physics.Raycast (ray, Mathf.Sqrt (deltaX * deltaX + deltaY * deltaY), collisionMask)) {
grounded = true;
deltaY = 0;
}
}
Vector2 finalTransform = new Vector2 (deltaX, deltaY);
transform.Translate (finalTransform);
}
public void SetCollider(Vector3 size, Vector3 center)
{
collider.size = size;
collider.center = center;
s = size * colliderScale;
c = center * colliderScale;
}
public void ResetCollider() {
SetCollider(originalSize,originalCentre);
}
}
using UnityEngine;
using System.Collections;
public class Ragdoll : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
<?php
//connect to the database
include 'mysqli_connect.php';
//get the input
if(($_REQUEST['username'] != null) && ($_REQUEST['password'] != null))
{
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$u = mysqli_real_escape_string($dbc, trim($username));
$securepass = sha1($password);
$check = "SELECT * FROM conquest_users WHERE email='$u'";
$check_r = mysqli_query($dbc, $check);
if(mysqli_num_rows($check_r) == 0)
{
//insert into database
$query = "INSERT INTO conquest_users (email, password, highscore) VALUES ('$u', '$securepass', 0)";
//get the results
$result = @mysqli_query($dbc, $query) or die('Query failed: '.mysql_error());
echo "registered";
}else{
echo "Invalid Email";
}
} else {
echo "Invalid access";
}
?>
using UnityEngine;
using System.Collections;
public class Sawblade : MonoBehaviour {
//public float speed = 300;
public Vector3 offset, rotationVelocity;
public float recycleOffset, spawnChance;
void Start () {
GameEventManager.GameOver += GameOver;
gameObject.SetActive(true);
}
// Update is called once per frame
void Update () {
if(transform.localPosition.x + recycleOffset < PlayerController.distanceTraveled)
{
gameObject.SetActive(false);
return;
}
//transform.Rotate (Vector3.forward * speed * Time.deltaTime, Space.World);
transform.Rotate(rotationVelocity * Time.deltaTime);
}
void OnTriggerEnter(Collider c)
{
if (c.tag == "Player")
{
c.GetComponent<Entity>().TakeDamage(10);
gameObject.SetActive(false);
}
}
public void SpawnIfAvailable (Vector3 position) {
if (gameObject.activeSelf || spawnChance <= Random.Range (0f, 100f)) {
return;
} else {
transform.localPosition = position + offset;
gameObject.SetActive (true);
}
}
private void GameOver () {
gameObject.SetActive(false);
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SkylineManager : MonoBehaviour {
public Transform prefab;
public int numberOfObjects;
public Vector3 startPosition;
public float recycleOffset;
private Vector3 nextPosition;
private Queue<Transform> objectQueue;
public Vector3 minSize, maxSize;
void Start () {
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
objectQueue = new Queue<Transform>(numberOfObjects);
for(int i = 0; i < numberOfObjects; i++){
objectQueue.Enqueue((Transform)Instantiate(
prefab, new Vector3(0f, 0f, -100f), Quaternion.identity));
}
enabled = false;
}
void Update () {
if (objectQueue.Peek().localPosition.x + recycleOffset < PlayerController.distanceTraveled) {
Recycle();
}
}
private void Recycle () {
Vector3 scale = new Vector3(
Random.Range(minSize.x, maxSize.x),
Random.Range(minSize.y, maxSize.y),
Random.Range(minSize.z, maxSize.z));
Vector3 position = nextPosition;
position.x += scale.x * 0.5f;
position.y += scale.y * 0.5f;
Transform o = objectQueue.Dequeue();
o.localScale = scale;
o.localPosition = position;
nextPosition.x += scale.x;
objectQueue.Enqueue(o);
}
private void GameStart () {
nextPosition = startPosition;
for(int i = 0; i < numberOfObjects; i++){
Recycle();
}
enabled = true;
}
private void GameOver () {
enabled = false;
}
}
<?php
//connect to the database
include 'mysqli_connect.php';
//get the input
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$u = mysqli_real_escape_string($dbc, trim($username));
//query the database
$query = "SELECT * FROM conquest_users WHERE email='$u' AND password=SHA1('$password')";
//echo $query;
//get the results
$result = mysqli_query($dbc, $query);
//test the results
if(mysqli_num_rows($result) == 1)
echo "right";
else
echo "wrong";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment