rev, v0.3
This commit is contained in:
@@ -41,6 +41,20 @@ public class Ball : MonoBehaviour
|
||||
float velocityMult = 1- Mathf.Clamp01(rb.linearVelocity.magnitude / maxWallStuckVelocity);
|
||||
|
||||
Debug.Log($"{collision.collider.name} hit ball @ {otherSpeed}, ball speed: {rb.linearVelocity.magnitude}");
|
||||
int mult=0;
|
||||
if(touchingB){
|
||||
mult++;
|
||||
}
|
||||
if(touchingT){
|
||||
mult++;
|
||||
}
|
||||
if(touchingL){
|
||||
mult++;
|
||||
}
|
||||
if(touchingR){
|
||||
mult++;
|
||||
}
|
||||
velocityMult *= mult;
|
||||
if (touchingR) {
|
||||
rb.AddForce(Vector2.left * otherSpeed *wallStuckFixForce * velocityMult * Time.deltaTime);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
@@ -24,10 +25,10 @@ public class GameManager : MonoBehaviour
|
||||
public EventTrigger gameInputPanel;
|
||||
public Rigidbody2D ball;
|
||||
public float puckForce = 20f;
|
||||
[Range(0f,1f)]
|
||||
public float puckForceMaxPoint = 0.75f;
|
||||
public AnimationCurve puckForceCurve = AnimationCurve.Linear(0,3,1,1);
|
||||
public float ballMoveTime = 3f;
|
||||
public float puckDragClamp = 5f;
|
||||
public float puckDragClampMax = 5f;
|
||||
public float puckDragMinClamp = 1f;
|
||||
|
||||
public int redScore,blueScore=0;
|
||||
|
||||
@@ -39,6 +40,8 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
[Header("Misc")]
|
||||
public List<Puck> pucks = new List<Puck>();
|
||||
public float curPuckPullForce;
|
||||
public int hitCounter = 0;
|
||||
|
||||
public static GameManager instance;
|
||||
void Awake()
|
||||
@@ -118,14 +121,22 @@ public class GameManager : MonoBehaviour
|
||||
Vector2 endPosition = pointerEventData.position;
|
||||
// Vector2 direction = endPosition - startPosition;
|
||||
Vector2 direction = selectedPuck.lineEnd;
|
||||
|
||||
if(direction.magnitude < puckDragMinClamp){
|
||||
selectedPuck = null;
|
||||
OnSelectedPuckChanged?.Invoke(null);
|
||||
startPosition = Vector2.zero;
|
||||
return;
|
||||
}
|
||||
if(coroutinePostLaunch != null){
|
||||
StopCoroutine(coroutinePostLaunch);
|
||||
}
|
||||
coroutinePostLaunch = StartCoroutine(CoroutinePostLaunch());
|
||||
|
||||
float force = puckForce * Time.deltaTime;
|
||||
Debug.Log($"launching puck at {direction}");
|
||||
curPuckPullForce = direction.magnitude;
|
||||
float force = puckForce * Time.deltaTime * puckForceCurve.Evaluate(curPuckPullForce);
|
||||
Debug.Log($"launching puck at {direction} with {force * -direction} force");
|
||||
selectedPuck.GetComponent<Rigidbody2D>().AddForce(-direction * force, ForceMode2D.Impulse);
|
||||
hitCounter++;
|
||||
|
||||
startPosition = Vector2.zero;
|
||||
selectedPuck = null;
|
||||
@@ -138,6 +149,10 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
PointerEventData pointerEventData = eventData as PointerEventData;
|
||||
curPosition = pointerEventData.position;
|
||||
|
||||
if(selectedPuck!=null){
|
||||
curPuckPullForce = selectedPuck.lineEnd.magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,14 +189,25 @@ public class GameManager : MonoBehaviour
|
||||
public void OnGoal(Team team){
|
||||
freezeInput=true;
|
||||
|
||||
if(hitCounter == 1){
|
||||
//kickoff goal
|
||||
Debug.Log("Kickoff goal");
|
||||
StartCoroutine(CoroutineOnGoal(team,true));//true = Kickoff goal, reset only the ball
|
||||
return;
|
||||
}
|
||||
if(team == Team.Blue){
|
||||
blueScore++;
|
||||
blueScoreText.text = blueScore.ToString();
|
||||
SelectedTeam = Team.Red;
|
||||
}else{
|
||||
redScore++;
|
||||
redScoreText.text = redScore.ToString();
|
||||
SelectedTeam = Team.Blue;
|
||||
}
|
||||
|
||||
OnTeamChanged?.Invoke(SelectedTeam);
|
||||
|
||||
|
||||
if(blueScore >= 3){
|
||||
gameOverPanel.SetActive(true);
|
||||
|
||||
@@ -194,11 +220,13 @@ public class GameManager : MonoBehaviour
|
||||
}else{
|
||||
StartCoroutine(CoroutineOnGoal(team));
|
||||
}
|
||||
|
||||
hitCounter = 0;
|
||||
}
|
||||
|
||||
bool freezeInput = false;
|
||||
|
||||
IEnumerator CoroutineOnGoal(Team team){
|
||||
IEnumerator CoroutineOnGoal(Team team, bool kickoff = false){
|
||||
if(coroutinePostLaunch!=null){
|
||||
StopCoroutine(coroutinePostLaunch);
|
||||
}
|
||||
@@ -216,15 +244,17 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
public void Reset()
|
||||
public void Reset(bool kickoff = false)
|
||||
{
|
||||
StartCoroutine(CoroutineReset());
|
||||
StartCoroutine(CoroutineReset(kickoff));
|
||||
}
|
||||
|
||||
IEnumerator CoroutineReset(){
|
||||
IEnumerator CoroutineReset(bool kickoff = false){
|
||||
float resetDuration = 0.5f;
|
||||
foreach(Puck puck in pucks){
|
||||
puck.Reset(resetDuration);
|
||||
if(!kickoff){
|
||||
foreach(Puck puck in pucks){
|
||||
puck.Reset(resetDuration);
|
||||
}
|
||||
}
|
||||
|
||||
ball.GetComponent<Ball>().Reset(resetDuration);
|
||||
|
||||
@@ -10,6 +10,21 @@ public class Goal : MonoBehaviour
|
||||
Ball ball = collision.gameObject.GetComponent<Ball>();
|
||||
Debug.Log(ball.name);
|
||||
GameManager.instance.OnGoal(team);
|
||||
}else if(collision.gameObject.CompareTag("Puck")){
|
||||
Debug.Log("Puck goal", gameObject);
|
||||
Puck puck = collision.gameObject.GetComponent<Puck>();
|
||||
Debug.Log(puck.name);
|
||||
puck.ScheduleReset();
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if(collision.gameObject.CompareTag("Puck")){
|
||||
Debug.Log("Puck exit goal", gameObject);
|
||||
Puck puck = collision.gameObject.GetComponent<Puck>();
|
||||
Debug.Log(puck.name);
|
||||
puck.UnscheduleReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-1
@@ -59,7 +59,7 @@ public class Puck : MonoBehaviour
|
||||
Vector3 worldEnd = Camera.main.ScreenToWorldPoint(new Vector3(GameManager.instance.curPosition.x, GameManager.instance.curPosition.y, Camera.main.nearClipPlane));
|
||||
|
||||
lineEnd = transform.InverseTransformPoint(worldEnd);
|
||||
float clamp = GameManager.instance.puckDragClamp;
|
||||
float clamp = GameManager.instance.puckDragClampMax;
|
||||
lineEnd = Vector2.ClampMagnitude(lineEnd, clamp);
|
||||
|
||||
// Only two points for the line
|
||||
@@ -105,6 +105,23 @@ public class Puck : MonoBehaviour
|
||||
{
|
||||
StartCoroutine(CoroutineReset(duration));
|
||||
}
|
||||
Coroutine coroutineScheduleReset;
|
||||
public void ScheduleReset(float duration = 0.5f){
|
||||
coroutineScheduleReset = StartCoroutine(CoroutineScheduleReset(duration));
|
||||
}
|
||||
|
||||
public void UnscheduleReset(){
|
||||
if(coroutineScheduleReset != null){
|
||||
StopCoroutine(coroutineScheduleReset);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CoroutineScheduleReset(float duration){
|
||||
while(GameManager.isMoving){
|
||||
yield return null;
|
||||
}
|
||||
Reset(duration);
|
||||
}
|
||||
|
||||
IEnumerator CoroutineReset(float duration){
|
||||
float t=0;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class StatCanvas : MonoBehaviour
|
||||
{
|
||||
public static StatCanvas instance;
|
||||
public TMP_Text txtVersion;
|
||||
void Awake()
|
||||
{
|
||||
if(instance!=null){
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
txtVersion.text = "v " + Application.version;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a49b5cb62dd2545408364e077bdf3a0a
|
||||
Reference in New Issue
Block a user