Skip to content

Instantly share code, notes, and snippets.

@AmmarTee
Last active January 15, 2021 10:14
Show Gist options
  • Save AmmarTee/e4ffdc213f2faf6a1f7d5179d59378eb to your computer and use it in GitHub Desktop.
Save AmmarTee/e4ffdc213f2faf6a1f7d5179d59378eb to your computer and use it in GitHub Desktop.
Our Bootcamp Scripts for Students
using UnityEngine;
public class cameraFollow : MonoBehaviour
{
public GameObject player;
public float offset;
// Update is called once per frame
void Update()
{
gameObject.transform.position = new Vector3(player.transform.position.x , gameObject.transform.position.y , player.transform.position.z + offset);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class coll : MonoBehaviour
{
public static bool isFinished;
public Text finish_lable;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Obs")){
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if (other.CompareTag("Fns"))
{
isFinished = true;
Time.timeScale = 0;
finish_lable.text = "Congratulations";
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
private void Start()
{
isFinished = false;
Time.timeScale = 1;
}
private void Update()
{
if (gameObject.transform.position.y < -10)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class forcingObject : MonoBehaviour
{
public Rigidbody rb;
void Start()
{
rb.useGravity = true;
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class gameMenuController : MonoBehaviour
{
// Start is called before the first frame update
public Animator anim;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
openMenu();
}
}
private void openMenu()
{
Time.timeScale = 0;
anim.Play("gameMenu");
}
public void closeMenu()
{
anim.Play("gameMenu_C");
Time.timeScale = 1;
}
public void exitfromLevel()
{
SceneManager.LoadScene(0);
Time.timeScale = 1;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class menuController : MonoBehaviour
{
public Animator anim;
private void Start()
{
Time.timeScale = 1;
StartCoroutine(animationController());
}
// Update is called once per frame
IEnumerator animationController()
{
yield return new WaitForSecondsRealtime(3);
anim.Play("Menu_SR");
yield return new WaitForSecondsRealtime(2);
anim.Play("Open_B");
}
public void startGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+1);
}
public void exitGame()
{
Application.Quit();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
private Rigidbody rb;
public float speed;
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// movementForce();
if (!coll.isFinished)
{
movementTranslate();
}
}
private void movementTranslate()
{
if (Input.GetKey(KeyCode.W))
{
gameObject.transform.Translate(new Vector3(0, 0, 1*speed),Space.World);
}
if (Input.GetKey(KeyCode.S))
{
gameObject.transform.Translate(new Vector3(0, 0, -1*speed), Space.World);
}
if (Input.GetKey(KeyCode.A))
{
gameObject.transform.Translate(new Vector3(-1*speed, 0, 0), Space.World);
}
if (Input.GetKey(KeyCode.D))
{
gameObject.transform.Translate(new Vector3(1*speed, 0, 0), Space.World);
}
}
private void movementForce()
{
if (Input.GetKey(KeyCode.W))
{
rb.AddForce(0, 0, 1 * speed, ForceMode.VelocityChange);
}
if (Input.GetKey(KeyCode.S))
{
rb.AddForce(0, 0, -1 * speed, ForceMode.VelocityChange);
}
if (Input.GetKey(KeyCode.A))
{
rb.AddForce(-1 * speed, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey(KeyCode.D))
{
rb.AddForce(1 * speed, 0, 0, ForceMode.VelocityChange);
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class score : MonoBehaviour
{
public Text score_Lable;
// Update is called once per frame
void Update()
{
int scoreInt = (int)gameObject.transform.position.z;
score_Lable.text = scoreInt.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment