mirror of
https://github.com/chibicitiberiu/frica-de-gaze
synced 2024-02-24 08:23:32 +00:00
Fixed everything, added sound, etc.
This commit is contained in:
34
FricaDeGaze/Assets/Scripts/AddSpider.cs
Normal file
34
FricaDeGaze/Assets/Scripts/AddSpider.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class AddSpider : MonoBehaviour {
|
||||
|
||||
// Use this for initialization
|
||||
public GameObject enemy;
|
||||
public SpiderMove sc;
|
||||
|
||||
float randomInterval = 5.0f;
|
||||
|
||||
IEnumerator Start()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
yield return new WaitForSeconds(Random.Range(randomInterval, 2 * randomInterval));
|
||||
|
||||
if (randomInterval > .2f)
|
||||
randomInterval -= randomInterval / 10;
|
||||
|
||||
Instantiate(enemy);
|
||||
|
||||
float scale = Random.Range(.5f / randomInterval, .5f / randomInterval);
|
||||
|
||||
enemy.transform.position = new Vector3(-4, 0, -4);
|
||||
enemy.transform.localScale = new Vector3(scale, scale, scale);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
8
FricaDeGaze/Assets/Scripts/AddSpider.cs.meta
Normal file
8
FricaDeGaze/Assets/Scripts/AddSpider.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ada97eb6567e9a6498bb1160924d034a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
29
FricaDeGaze/Assets/Scripts/BallCollisionWithSpider.cs
Normal file
29
FricaDeGaze/Assets/Scripts/BallCollisionWithSpider.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class BallCollisionWithSpider : MonoBehaviour {
|
||||
|
||||
public AudioSource SoundToPlay;
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.name.Contains ("Spider"))
|
||||
{
|
||||
Destroy (gameObject);
|
||||
Destroy (other.gameObject);
|
||||
|
||||
SoundToPlay.enabled = true;
|
||||
SoundToPlay.Play ();
|
||||
}
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11f62baee581a48498f4d97b47844f9e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
38
FricaDeGaze/Assets/Scripts/BallShoot.cs
Normal file
38
FricaDeGaze/Assets/Scripts/BallShoot.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class BallShoot : MonoBehaviour {
|
||||
|
||||
public GameObject Ball;
|
||||
public float ThrowSpeed = 10f;
|
||||
public AudioSource ThrowSound;
|
||||
|
||||
private float LastThrowTime = 0;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
Physics.gravity = new Vector3(0, -20, 0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
var direction = Camera.main.transform.forward;
|
||||
|
||||
if (Input.GetButton ("Fire1") && LastThrowTime + .05 < Time.timeSinceLevelLoad)
|
||||
{
|
||||
// Throw ball
|
||||
var ball = Instantiate(Ball) as GameObject;
|
||||
ball.transform.position = Camera.main.transform.position + direction;
|
||||
ball.rigidbody.AddForce(direction * ThrowSpeed, ForceMode.Impulse);
|
||||
|
||||
LastThrowTime = Time.timeSinceLevelLoad;
|
||||
|
||||
// Play sound
|
||||
if (ThrowSound != null)
|
||||
ThrowSound.Play();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
8
FricaDeGaze/Assets/Scripts/BallShoot.cs.meta
Normal file
8
FricaDeGaze/Assets/Scripts/BallShoot.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e5915773de69b14fb8e8a5f0fdd1d3d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
43
FricaDeGaze/Assets/Scripts/SpiderMove.cs
Normal file
43
FricaDeGaze/Assets/Scripts/SpiderMove.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SpiderMove : MonoBehaviour {
|
||||
|
||||
public float Speed;
|
||||
|
||||
Vector3 source;
|
||||
Vector3 destination;
|
||||
|
||||
Vector3 generaterandom()
|
||||
{
|
||||
// Generate positions outside box
|
||||
float x, z;
|
||||
x = Random.Range(-4f, 4f);
|
||||
z = -Random.Range(-4f, 4f);
|
||||
|
||||
return new Vector3 (x, .2f, z);
|
||||
}
|
||||
|
||||
IEnumerator Start () {
|
||||
|
||||
|
||||
source = generaterandom ();
|
||||
destination = generaterandom ();
|
||||
|
||||
gameObject.transform.forward = destination - source;
|
||||
gameObject.transform.position = source;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update ()
|
||||
{
|
||||
gameObject.transform.position += gameObject.transform.forward * Speed;
|
||||
|
||||
if (Mathf.Abs(gameObject.transform.position.x) > 5f
|
||||
|| Mathf.Abs(gameObject.transform.position.y) > 5f
|
||||
|| Mathf.Abs(gameObject.transform.position.z) > 5f)
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
8
FricaDeGaze/Assets/Scripts/SpiderMove.cs.meta
Normal file
8
FricaDeGaze/Assets/Scripts/SpiderMove.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fd658d74558a1a4090b8cef4b940993
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
Reference in New Issue
Block a user