using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Controller : MonoBehaviour
{
public float speed = 50;
public int trueRange = 50;
public Text minT, maxT, currentText, winORloseText,levelText;
public Image againPanel , nextPanel , endPanel, levelPanelBack;
Vector3 rotationPoint = Vector3.zero;
float temp;
int maxWinD;
int minWinD;
bool hold;
int Lnum = 1;
// Start is called before the first frame update
void Start()
{
Lnum = PlayerPrefs.GetInt("Level num", 1);
trueRange -= (Lnum - 1) * 10;
speed *= 1+((float)(Lnum-1)/2);
//speed *= Lnum;
levelText.text = "speed = " + speed + " L E V E L " + Lnum + " range = " + trueRange;
BackColor();
SetRange();
}
// Update is called once per frame
void Update()
{
temp = Mathf.Round(transform.rotation.eulerAngles.z);
currentText.text = "" + temp;
if (hold)
{
transform.RotateAround(rotationPoint, Vector3.forward, speed * Time.deltaTime);
}
}
void BackColor()
{
switch (Lnum)
{
case 1:
levelPanelBack.color = new Color32(0, 255,50,255);
break;
case 2:
levelPanelBack.color = new Color32(0, 255, 228, 255);
break;
case 3:
levelPanelBack.color = new Color32(0, 50, 255, 255);
break;
case 4:
levelPanelBack.color = new Color32(160, 0, 255, 255);
break;
case 5:
levelPanelBack.color = new Color32(255, 0, 130, 255);
break;
}
}
void SetRange()
{
int winD = Random.Range((trueRange / 2), 360 - (trueRange / 2));
maxWinD = winD + (trueRange / 2);
minWinD = winD - (trueRange / 2);
minT.text = "Min = " + minWinD;
maxT.text = "Max = " + maxWinD;
}
void WinCheck()
{
if (temp <= maxWinD && temp >= minWinD)
{
winORloseText.text = "WIN";
if (trueRange > 10)
nextPanel.gameObject.SetActive(true);
else
endPanel.gameObject.SetActive(true);
}
else
{
winORloseText.text = "LOSE";
againPanel.gameObject.SetActive(true);
}
}
public void StartRotate()
{
hold = true;
}
public void EndRotate()
{
hold = false;
WinCheck();
}
public void Next()
{
Lnum += 1;
PlayerPrefs.SetInt("Level num", Lnum);
SceneManager.LoadScene(0);
}
public void Again()
{
SceneManager.LoadScene(0);
}
public void GotoLevel1()
{
PlayerPrefs.DeleteAll();
SceneManager.LoadScene(0);
}
}In this game, by touching the mobile screen, you move a brush and spray paint and draw graffiti on the wall. During the game, you must be careful not to collide with obstacles.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
Rigidbody2D playerRig;
float _speed = 0;
Animator boyAnimator;
SpriteRenderer spriteRenderer;
public float speed = 10;
public static float playerXpos;
// Start is called before the first frame update
void Start()
{
playerRig = gameObject.GetComponent<Rigidbody2D>();
boyAnimator = GetComponentInChildren<Animator>();
spriteRenderer = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
playerXpos = transform.position.x;
}
private void FixedUpdate()
{
playerRig.velocity = new Vector2(_speed, playerRig.velocity.y);
}
public void RunR()
{
_speed = speed;
boyAnimator.SetFloat("speed", speed);
spriteRenderer.flipX = true;
}
public void RunL()
{
_speed = -speed;
boyAnimator.SetFloat("speed", speed);
spriteRenderer.flipX = false;
}
public void Stop()
{
_speed = 0;
boyAnimator.SetFloat("speed", 0);
}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Alien : MonoBehaviour
{
Animator alienAnimator;
public float speed = 2;
float i = 0;
// Start is called before the first frame update
void Start()
{
alienAnimator = GetComponent<Animator>();
}
private void Update()
{
transform.Translate(new Vector2(i * speed * Time.deltaTime, 0));
}
private void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
{
alienAnimator.SetBool("Run", true);
}
else if(collision.gameObject.tag == "Destroy")
{
Destroy(gameObject);
}
}
public void StartRun()
{
i = (Player.playerXpos - transform.position.x) / Mathf.Abs(Player.playerXpos - transform.position.x);
//Debug.Log(i);
//transform.rotation = new Quaternion(0, Mathf.Acos(i), 0, 0);
GetComponent<SpriteRenderer>().flipX = i < 0;
}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InstantiateObjects : MonoBehaviour
{
public GameObject flyingSaucer;
public GameObject[] alien;
int r;
// Start is called before the first frame update
void Start()
{
StartCoroutine(Inst());
}
// Update is called once per frame
void Update()
{
r = Random.Range(0, alien.Length);
}
IEnumerator Inst()
{
yield return new WaitForSeconds(2f);
flyingSaucer.SetActive(true);
yield return new WaitForSeconds(1.5f);
for(int i =0; i<10; i++)
{
Instantiate(alien[r],transform.position,transform.rotation);
yield return new WaitForSeconds(5f);
}
flyingSaucer.SetActive(false);
}
}/*==============================================================================
Copyright (c) 2017 PTC Inc. All Rights Reserved.
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Protected under copyright and other laws.
==============================================================================*/
using UnityEngine;
using Vuforia;
/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
///
/// Changes made to this file could be overwritten when upgrading the Vuforia version.
/// When implementing custom event handler behavior, consider inheriting from this class instead.
/// </summary>
public class MyTrackableEventHandler : MonoBehaviour, ITrackableEventHandler
{
#region PROTECTED_MEMBER_VARIABLES
protected TrackableBehaviour mTrackableBehaviour;
protected TrackableBehaviour.Status m_PreviousStatus;
protected TrackableBehaviour.Status m_NewStatus;
#endregion // PROTECTED_MEMBER_VARIABLES
#region UNITY_MONOBEHAVIOUR_METHODS
protected virtual void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
protected virtual void OnDestroy()
{
if (mTrackableBehaviour)
mTrackableBehaviour.UnregisterTrackableEventHandler(this);
}
#endregion // UNITY_MONOBEHAVIOUR_METHODS
#region PUBLIC_METHODS
/// <summary>
/// Implementation of the ITrackableEventHandler function called when the
/// tracking state changes.
/// </summary>
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
m_PreviousStatus = previousStatus;
m_NewStatus = newStatus;
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
OnTrackingFound();
}
else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
newStatus == TrackableBehaviour.Status.NO_POSE)
{
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
OnTrackingLost();
}
else
{
// For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND
// Vuforia is starting, but tracking has not been lost or found yet
// Call OnTrackingLost() to hide the augmentations
OnTrackingLost();
}
}
#endregion // PUBLIC_METHODS
#region PROTECTED_METHODS
public GameObject obj;
public Transform pos;
GameObject _obj;
protected virtual void OnTrackingFound()
{
_obj = Instantiate(obj, pos.position, pos.rotation);
_obj.transform.parent = gameObject.transform;
//var rendererComponents = GetComponentsInChildren<Renderer>(true);
//var colliderComponents = GetComponentsInChildren<Collider>(true);
//var canvasComponents = GetComponentsInChildren<Canvas>(true);
//// Enable rendering:
//foreach (var component in rendererComponents)
// component.enabled = true;
//// Enable colliders:
//foreach (var component in colliderComponents)
// component.enabled = true;
//// Enable canvas':
//foreach (var component in canvasComponents)
// component.enabled = true;
}
protected virtual void OnTrackingLost()
{
Destroy(_obj);
GameObject[] alienObj = GameObject.FindGameObjectsWithTag("alien");
foreach (GameObject alObj in alienObj)
{
Destroy(alObj);
}
//var rendererComponents = GetComponentsInChildren<Renderer>(true);
//var colliderComponents = GetComponentsInChildren<Collider>(true);
//var canvasComponents = GetComponentsInChildren<Canvas>(true);
//// Disable rendering:
//foreach (var component in rendererComponents)
// component.enabled = false;
//// Disable colliders:
//foreach (var component in colliderComponents)
// component.enabled = false;
//// Disable canvas':
//foreach (var component in canvasComponents)
// component.enabled = false;
}
#endregion // PROTECTED_METHODS
}using System.Collections;
using UnityEngine;
public class Ball : MonoBehaviour
{
public GameObject eatEffect;
public Animator eatAnim;
public AudioSource padAudio;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "Pad")
{
padAudio.Play();
}
else if (collision.tag == "Player")
{
StartCoroutine(StartEat());
}
else if(collision.tag == "Border")
{
gameObject.SetActive(false);
}
}
IEnumerator StartEat()
{
eatAnim.SetTrigger("eat");
eatEffect.SetActive(true);
yield return new WaitForSeconds(.2f);
gameObject.GetComponent<SpriteRenderer>().enabled = false;
yield return new WaitForSeconds(1f);
eatEffect.SetActive(false);
gameObject.GetComponent<SpriteRenderer>().enabled = true;
gameObject.SetActive(false);
}
}using System;
using UnityEngine;
using UnityEngine.UI;
public class Run : MonoBehaviour
{
public GameObject ball;
Vector3 ballStartPos;
public Text textX;
public Text textY;
void Start()
{
ballStartPos = ball.transform.position;
}
public void PlayBall()
{
int x = Convert.ToInt32(textX.text);
int y = Convert.ToInt32(textY.text);
ball.GetComponent<Rigidbody2D>().AddForce(new Vector2(x*100 , y*100));
}
public void REstart()
{
ball.SetActive(true);
ball.transform.position = ballStartPos + new Vector3(0, 1, 0);
ball.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
ball.GetComponent<Rigidbody2D>().angularVelocity = 0;
}
}using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
[Range(0, 1)]
public float smoothSpeed = 0.125f;
public Vector3 offset;
void FixedUpdate()
{
if (target != null)
{
Vector3 desiredPosition = new Vector3(transform.position.x, target.position.y, transform.position.z) + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
//transform.LookAt(target);
}
}
}using UnityEngine;
using UnityEngine.SceneManagement;
public class RocketRun : MonoBehaviour
{
private Rigidbody rg;
[SerializeField]
private float force, speed;
private AudioSource rocketAudio;
public GameObject rocketParticle;
public GameObject rocketlight;
public string nextLevel, startLevel;
public GameObject ExplosionEffect, finishSound;
string state = "Play";
private void Awake()
{
rg = GetComponent<Rigidbody>();
rocketAudio = GetComponent<AudioSource>();
}
private void Update()
{
if (state == "Play")
{
MoveLRRocket();
RocketSoundAndParticel();
}
else
{
Stop();
}
}
private void FixedUpdate()
{
if (state == "Play")
MoveUpRocket();
}
private void OnCollisionEnter(Collision collision)
{
if (state == "Play")
{
switch (collision.gameObject.tag)
{
case "Dead":
Debug.Log("Dead");
state = "dead";
Dead();
break;
case "Finish":
Debug.Log("Finish");
state = "finish";
Instantiate(finishSound);
Invoke("RunNextLevel", 3f);
break;
}
}
}
void MoveUpRocket()
{
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
rg.AddRelativeForce(Vector3.forward * force * Time.fixedDeltaTime);
}
}
void MoveLRRocket()
{
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(-Vector3.up * speed * Time.deltaTime);
}
else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.up * speed * Time.deltaTime);
}
}
void RocketSoundAndParticel()
{
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
{
rocketAudio.Play();
rocketParticle.SetActive(true);
rocketlight.SetActive(true);
}
if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
{
rocketAudio.Stop();
rocketParticle.SetActive(false);
rocketlight.SetActive(false);
}
}
void Stop()
{
rocketAudio.Stop();
rocketParticle.SetActive(false);
rocketlight.SetActive(false);
}
void RunNextLevel()
{
SceneManager.LoadScene(nextLevel);
}
void Dead()
{
Instantiate(ExplosionEffect, transform.position - new Vector3(0, 0, 1), transform.rotation);
gameObject.GetComponent<MeshRenderer>().enabled = false;
Invoke("RunStartLevel", 2f);
}
void RunStartLevel()
{
SceneManager.LoadScene(startLevel);
}
}using UnityEngine;
public class RockTranslate : MonoBehaviour
{
[SerializeField] [Range(0, 10)] float speed;
// Update is called once per frame
void Update()
{
transform.Translate(new Vector3(1, 0, 0) * speed * Time.deltaTime);
if (transform.position.x < -9 || transform.position.x > 9)
speed = -speed;
}
}using UnityEngine;
public class Rotate : MonoBehaviour
{
public Vector3 ro;
void Update()
{
transform.Rotate(ro * Time.deltaTime);
}
}using System.Collections;
using UnityEngine;
public class EatCupcake : MonoBehaviour
{
public GameObject eatEffect;
public Animator eatAnim;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Cupcake")
{
StartCoroutine(StartEat(collision));
}
}
IEnumerator StartEat(Collider2D collision)
{
eatAnim.SetTrigger("eat");
collision.gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
collision.gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
yield return new WaitForSeconds(.6f);
eatEffect.SetActive(true);
yield return new WaitForSeconds(.1f);
Destroy(collision.gameObject);
yield return new WaitForSeconds(1f);
eatEffect.SetActive(false);
}
}using UnityEngine;
public class Drog_Drop_mouse : MonoBehaviour
{
// Update is called once per frame
void Update()
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetKey(KeyCode.Mouse0) && (GetComponent<Collider2D>() == Physics2D.OverlapPoint(mousePos)))
{
transform.position = new Vector2(mousePos.x, mousePos.y);
}
}
}using UnityEngine;
public class player : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Idle();
}
if (Input.GetMouseButtonDown(1))
{
Bend();
}
if (Input.GetMouseButtonDown(2))
{
Walk();
}
}
public void Idle()
{
anim.SetBool("bend", false);
anim.SetBool("walk", false);
}
public void Bend()
{
anim.SetBool("bend", true);
anim.SetBool("walk", false);
}
public void Walk()
{
anim.SetBool("bend", false);
anim.SetBool("walk", true);
}
}using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed;
float x,y;
// Update is called once per frame
void Update () {
if (Accident.health > 0 && !End.endState)
{
x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
y = Input.GetAxis("Vertical") * speed * Time.deltaTime;
transform.Translate(x, y, 0);
}
else if (Accident.health > 0)
{
transform.Translate(-0.5f * Time.deltaTime, 0, 0);
}
}
}using UnityEngine;
using System.Collections;
public class Accident : MonoBehaviour {
public GameObject redPanel;
public GameObject losePanel;
public float redTime = .3f;
public AudioSource audioSource;
public AudioClip loseClip;
public static int health = 3;
void OnCollisionEnter2D (Collision2D col){
if (col.gameObject.tag == "Wall") {
StartCoroutine(Red());
GetComponent<AudioSource>().Play();
health--;
if (health <= 0)
{
Lose();
}
}
}
IEnumerator Red()
{
redPanel.SetActive(true);
yield return new WaitForSeconds(redTime);
redPanel.SetActive(false);
}
void Lose()
{
losePanel.SetActive(true);
audioSource.clip = loseClip;
audioSource.Play();
Destroy(gameObject, 5);
}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Health : MonoBehaviour
{
public GameObject[] healthUI = new GameObject[3];
// Update is called once per frame
void Update()
{
switch (Accident.health)
{
case 2:
healthUI[2].SetActive(false);
break;
case 1:
healthUI[1].SetActive(false);
break;
case 0:
healthUI[0].SetActive(false);
break;
}
}
}using UnityEngine;
using System.Collections;
public class End : MonoBehaviour {
public GameObject winPanel;
public AudioSource audioSource;
public AudioClip winClip;
public static bool endState;
void OnTriggerEnter2D (Collider2D col){
if (col.gameObject.tag == "Player") {
winPanel.SetActive(true);
audioSource.clip = winClip;
audioSource.Play();
endState = true;
Destroy(col.gameObject, 5);
}
}
}using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
void FixedUpdate ()
{
Vector3 desiredPosition = target.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
//transform.LookAt(target);
}
}using UnityEngine;
using System.Collections;
public class Sheep_sc : MonoBehaviour {
public float speed;
public float jump;
public AudioClip[] jumpAudioClip;
AudioSource jumpAudio;
public GameObject groundCheck;
public float groundCheck_r;
public LayerMask layerMask;
bool ground;
bool dudoubleJump;
private void Start()
{
jumpAudio = gameObject.GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (!End.end)
{
ground = Physics2D.OverlapCircle(groundCheck.transform.position, groundCheck_r, layerMask);
if (ground)
{
dudoubleJump = false;
}
if (Input.GetKeyDown(KeyCode.Space) && ground)
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
jumpAudio.clip = jumpAudioClip[0];
jumpAudio.Play();
}
if (Input.GetKeyDown(KeyCode.Space) && !ground && !dudoubleJump)
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
dudoubleJump = true;
jumpAudio.clip = jumpAudioClip[1];
jumpAudio.Play();
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(speed, GetComponent<Rigidbody2D>().velocity.y);
gameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(-speed, GetComponent<Rigidbody2D>().velocity.y);
gameObject.transform.rotation = new Quaternion(0, 180, 0, 0);
}
}
}
}using UnityEngine;
using System.Collections;
public class kill_s : MonoBehaviour {
public GameObject player;
public GameObject checkPoint;
void OnTriggerEnter2D(Collider2D col){
if (col.tag == "Player") {
gameObject.GetComponent<AudioSource>().Play();
player.transform.position = checkPoint.transform.position;
}
}
}using UnityEngine;
public class End : MonoBehaviour
{
public GameObject winPanel;
public AudioClip winAudioClip;
public AudioSource winAudio;
public static bool end = false;
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "Player")
{
end = true;
winAudio.clip = winAudioClip;
winAudio.Play();
winAudio.loop = false;
Destroy(gameObject);
winPanel.SetActive(true);
}
}
}