https://github.com/tomitrescak/unity-tutorial-blockbuster
https://github.com/tomitrescak/unity-tutorial-blockbuster
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tomitrescak/unity-tutorial-blockbuster
- Owner: tomitrescak
- Created: 2015-07-28T11:44:05.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-28T03:53:55.000Z (almost 9 years ago)
- Last Synced: 2025-02-07T19:34:58.328Z (4 months ago)
- Language: C#
- Homepage:
- Size: 18.3 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Unity3D Tutorial - BlockBuster
PDF Tutorial on how to create this game can be found here [https://github.com/tomitrescak/Unity-Tutorial-BlockBuster/blob/master/Tutorial-Chapter2.zip](https://github.com/tomitrescak/Unity-Tutorial-BlockBuster/blob/master/Tutorial-Chapter2.zip).
The tutorial comec from the book from Packt publishing, which you are encouraged to buy and use for learning.
Script for camera controls (attach to `MainCamera`)
```csharp
using UnityEngine;
using System.Collections;public class CameraMovement : MonoBehaviour {
public float speed = 1;// Update is called once per frame
void Update () {
// read key and move according to direction given in the movement vector
if (Input.GetKey (KeyCode.UpArrow) || Input.GetKey (KeyCode.W)) {
transform.Translate(new Vector3(0f, 0.01 * speed, 0f));
} else if (Input.GetKey (KeyCode.DownArrow) || Input.GetKey (KeyCode.S)) {
// don't let camera move under ground
if (transform.position.y > 0.5) {
transform.Translate(new Vector3(0f, -0.01 * speed, 0f));
}
} else if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.A)) {
transform.Translate(new Vector3(-0.01 * speed, 0f, 0f));
} else if (Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D)) {
transform.Translate(new Vector3(0.01 * speed, 0f, 0f));
}
}
}
```Script for shooting (Attach to `MainCamera`):
```csharp
using UnityEngine;
using System.Collections;public class ShootBullet : MonoBehaviour {
public GameObject bullet;
public float speed = 30f;
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) {
var go = Instantiate(bullet, this.transform.position, Quaternion.identity) as GameObject;
var instance = go.GetComponent();
instance.velocity = transform.forward * speed;
}
}
}
```Script for the bullet (Attach to `Bullet`)
```csharp
using UnityEngine;
using System.Collections;public class DestroyByTime : MonoBehaviour
{
public float lifetime;void Start ()
{
Destroy (gameObject, lifetime);
}
}
```