Skip to content

Commit

Permalink
UnityEngineScripts
Browse files Browse the repository at this point in the history
  • Loading branch information
thesaravanakumar committed Jun 15, 2021
1 parent 4b8861a commit 43a9d93
Show file tree
Hide file tree
Showing 54 changed files with 1,251 additions and 0 deletions.
8 changes: 8 additions & 0 deletions UnityFolderScripts/AIScripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions UnityFolderScripts/AIScripts/AI Damage.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterCarDamage : MonoBehaviour
{
public void OnCollisionEnter2D(Collision2D other) //if we collide with police car
{
if (other.gameObject.tag == "Player")
{
MonsterCarHealthManager.instance.DamageMonsterCar();
}
}
}
11 changes: 11 additions & 0 deletions UnityFolderScripts/AIScripts/AI Damage/MonsterCarDamage.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions UnityFolderScripts/AIScripts/AI Health.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions UnityFolderScripts/AIScripts/AI Health/MonsterCarHealthManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterCarHealthManager : MonoBehaviour
{

public static MonsterCarHealthManager instance;
public int currentHealth;
public int maxHealth;
public GameObject explosion;
public AudioSource carExplosion;
public void Awake()
{
instance = this;
}
private void Start()
{
currentHealth = maxHealth;
}
public void DamageMonsterCar()
{
currentHealth--;
if (currentHealth <= 0)
{
Instantiate(explosion, transform.position, transform.rotation);
gameObject.SetActive(false);
carExplosion.Play();
GameManager.instance.KillMonsterCar();
}
}
public void Respawn()
{
gameObject.SetActive(true);
currentHealth = maxHealth + 1;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions UnityFolderScripts/AIScripts/AICars.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AICars : MonoBehaviour
{
public float accelerator;
public float turnpower = 1;
public float turnspeed = 4;
Rigidbody2D rb;
internal bool isAIMovement;
private float friction = 1.5f;
private float currentSpeed;
private Vector2 curSpeed;
float currentAcc;
private bool isMoving;

public AudioSource engine;
public float maxEngineSound;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
currentAcc = accelerator;
}

private void Update()
{
if (engine != null)
{
engine.pitch=1f+((rb.velocity.magnitude / maxEngineSound) * 3f) ;
}
}

// Update is called once per frame
void FixedUpdate()
{
if (isMoving)
{
rb.AddForce(transform.up * currentAcc);
}
if (!isMoving)
{
rb.drag = friction * 2;
}
}

public void Movement(string turning,bool isPaddlePressed)
{
if (turning == "left")
{
transform.Rotate(Vector3.forward * (currentSpeed + currentSpeed));
}
else if (turning == "right")
{
transform.Rotate(Vector3.forward * -(currentSpeed + currentSpeed));
}
if (isPaddlePressed)
{
isMoving = true;
}

currentSpeed = curSpeed.magnitude / turnspeed;
curSpeed = new Vector2(rb.velocity.x, rb.velocity.y);
}
}
11 changes: 11 additions & 0 deletions UnityFolderScripts/AIScripts/AICars.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions UnityFolderScripts/AIScripts/AIMovement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AIMovement : MonoBehaviour
{
List<GameObject> routes;
private Vector3 nextPoint;
public GameObject AIPathHolder;
private bool isAccPressed = false;
AICars driver;
int totalWayPoints;
int currentIndex;
private bool nextPos;
private string turning;
AIPathway wayPoint;
internal Transform currentWayPoint;

// Start is called before the first frame update
void Start()
{
driver = GetComponent<AICars>();
if (AIPathHolder != null)
{
driver.isAIMovement = true;
wayPoint = AIPathHolder.GetComponent<AIPathway>();
routes = wayPoint.route;
currentIndex = 0;
totalWayPoints = routes.Count;
currentWayPoint = routes[0].transform;
}
}

// Update is called once per frame
void Update()
{
if (!nextPos)
{
nextPoint = currentWayPoint.position;
nextPos = true;
}
Vector3 relativeVector = transform.InverseTransformPoint(nextPoint);
turning = null;

if (relativeVector.x > 0.5f)
{
turning = "right";
}
else if (relativeVector.x < -0.5f)
{
turning = "left";
}
float dist = Vector2.Distance(transform.position, nextPoint);
isAccPressed = true;
if (dist < 2)
{
currentIndex++;
if (currentIndex >= totalWayPoints)
{
currentIndex = 0;
}
currentWayPoint = routes[currentIndex].transform;
nextPos = false;
}
}

private void FixedUpdate()
{
if (driver.isAIMovement)
{
driver.Movement(turning, isAccPressed);
}
}
}
11 changes: 11 additions & 0 deletions UnityFolderScripts/AIScripts/AIMovement.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions UnityFolderScripts/AIScripts/AIPathway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[ExecuteInEditMode]
public class AIPathway : MonoBehaviour
{
public List<GameObject> route;
public bool drawLine = true;
private void Awake()
{
if (route == null)
{
route = new List<GameObject>();
}
}

// Update is called once per frame
void Update()
{
#if UNITY_EDITOR
if (!EditorApplication.isPlaying)
{
if (route == null)
{
route = new List<GameObject>();
}
route.Clear();
foreach (Transform node in transform)
{
route.Add(node.gameObject);
}
}
if (route != null && route.Count > 1)
{
if (drawLine)//for checkbox
{
DrawLine();
}
}
#endif
}
private void DrawLine()
{
int index = 0;
Vector3 lastPos = route[index].transform.position;
for (int i = 0; i < route.Count; i++)
{
Debug.DrawLine(lastPos, route[index].transform.position);
lastPos = route[index].transform.position;
if (index == route.Count - 1)
{
Debug.DrawLine(lastPos, route[0].transform.position);
}
index++;
}
}
}
11 changes: 11 additions & 0 deletions UnityFolderScripts/AIScripts/AIPathway.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions UnityFolderScripts/AIScripts/AIVictoryTriggers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AIVictoryFullMonsterTruck : MonoBehaviour
{
public int currentLap;
public int maxLap;

// Start is called before the first frame update
void Start()
{
currentLap = maxLap;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "FullMonsterCar")
{
currentLap--;
if (currentLap <= 0)
{
SceneManager.LoadScene("AIVictory");
}
}
}


}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43a9d93

Please sign in to comment.