Import existing Unity project
This commit is contained in:
26
Assets/Scripts/ForceZone.cs
Normal file
26
Assets/Scripts/ForceZone.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ForceZone : MonoBehaviour
|
||||
{
|
||||
public float force = 0;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
Vector3 direction = other.transform.position - this.transform.position;
|
||||
Debug.DrawRay(this.transform.position, direction);
|
||||
other.transform.GetComponent<Rigidbody>().AddForce(direction.normalized * this.force * Time.deltaTime, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ForceZone.cs.meta
Normal file
11
Assets/Scripts/ForceZone.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ee5ed52ae75cde4cadf0d7de9efa9f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/Scripts/GameManager.cs
Normal file
44
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public int scorePlayer1 = 0;
|
||||
public int scorePlayer2 = 0;
|
||||
|
||||
public Transform player1;
|
||||
public Transform player2;
|
||||
public Transform ball;
|
||||
|
||||
public Transform player1Initial, player2Initial, ballInitial;
|
||||
|
||||
/* UI */
|
||||
public Text scoreLabel;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.player1Initial = new GameObject().transform;
|
||||
this.player1Initial.position = this.player1.position;
|
||||
|
||||
this.player2Initial = new GameObject().transform;
|
||||
this.player2Initial.position = this.player2.position;
|
||||
|
||||
this.ballInitial = new GameObject().transform;
|
||||
this.ballInitial.position = this.ball.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
this.scoreLabel.text = "Score: " + this.scorePlayer1 + " : " + this.scorePlayer2;
|
||||
}
|
||||
|
||||
public void ResetPositions()
|
||||
{
|
||||
this.player1.position = this.player1Initial.position;
|
||||
this.player2.position = this.player2Initial.position;
|
||||
this.ball.position = this.ballInitial.position;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager.cs.meta
Normal file
11
Assets/Scripts/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55bf84c610791ef4080484d67d35c0c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/Scripts/Goal.cs
Normal file
38
Assets/Scripts/Goal.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Goal : MonoBehaviour
|
||||
{
|
||||
public GameManager gm;
|
||||
public int playerNumber = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.gm = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.transform.tag == "Ball")
|
||||
{
|
||||
if (this.playerNumber == 1)
|
||||
{
|
||||
this.gm.scorePlayer2 += 1;
|
||||
}
|
||||
if (this.playerNumber == 2)
|
||||
{
|
||||
this.gm.scorePlayer1 += 1;
|
||||
}
|
||||
|
||||
this.gm.ResetPositions();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Goal.cs.meta
Normal file
11
Assets/Scripts/Goal.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84a13b8b8e155f749845dd4b123f388e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/PlayerController.cs
Normal file
63
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public string playerNumber;
|
||||
public float rotationSpeed = 100;
|
||||
public float movementSpeed = 100;
|
||||
public Rigidbody rb;
|
||||
public GameObject forceZone;
|
||||
public float boostSpeed = 0;
|
||||
public float boostDuration = 0;
|
||||
public float lastBoostTime = 0;
|
||||
public bool lockBoost = false;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
float rotationDirection = Input.GetAxis("Horizontal" + this.playerNumber);
|
||||
float movementDirection = Input.GetAxis("Vertical" + this.playerNumber);
|
||||
|
||||
if (rotationDirection > 0)
|
||||
{
|
||||
transform.Rotate(Vector3.up, this.rotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (rotationDirection < 0)
|
||||
{
|
||||
transform.Rotate(Vector3.up, -this.rotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (movementDirection > 0)
|
||||
{
|
||||
this.rb.AddRelativeForce(Vector3.forward * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
if (movementDirection < 0)
|
||||
{
|
||||
this.rb.AddRelativeForce(Vector3.back * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
if (Input.GetButtonDown("Boost" + this.playerNumber) && !this.lockBoost)
|
||||
{
|
||||
this.rb.AddRelativeForce(Vector3.forward * this.boostSpeed * Time.deltaTime, ForceMode.Impulse);
|
||||
this.forceZone.SetActive(true);
|
||||
this.lastBoostTime = Time.time;
|
||||
this.lockBoost = true;
|
||||
}
|
||||
|
||||
if (Time.time > (this.lastBoostTime + this.boostDuration))
|
||||
{
|
||||
this.lockBoost = false;
|
||||
this.forceZone.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerController.cs.meta
Normal file
11
Assets/Scripts/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d40c13a2057643a48b276db2829a33fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Assets/Scripts/desktop.ini.meta
Normal file
7
Assets/Scripts/desktop.ini.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5aa7199fb75a98468edf512cd64a871
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user