Added basic jump mechanic for slimes and prevention from going over the border, added tile hiding to increase performance

This commit is contained in:
finnchen123
2025-11-16 20:56:51 +01:00
parent c00a01c8d6
commit a8cca74fc4
10 changed files with 136 additions and 33 deletions

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
namespace Assets.Scripts.InteractableObjects
{
@@ -15,6 +16,53 @@ namespace Assets.Scripts.InteractableObjects
BasicSlime slime;
SlimeFactory factory = new SlimeFactory();
public SlimeType slimeType;
bool isJumping;
Stopwatch jumpTimer;
// Start is called before the first frame update
void Start()
{
isJumping = false;
jumpTimer = new Stopwatch();
//Nothing
}
// Update is called once per frame
void Update()
{
if (gameObject.activeSelf)
{
if (!isJumping)
{
jumpTimer.Start();
isJumping = true;
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(rand.Next(-5, 5), 10, rand.Next(-5, 5)), ForceMode.Impulse);
//gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(5, 10, 5), ForceMode.Impulse);
}
if (jumpTimer.ElapsedMilliseconds >= 5000)
{
jumpTimer.Reset();
isJumping = false;
}
if (gameObject.transform.position.x > 1000 || gameObject.transform.position.x > 5000 || gameObject.transform.position.x > 5000)
{
UnityEngine.Debug.Log("BUG!");
}
}
}
void OnTriggerExit(Collider col)
{
if (col.name.Contains("_") && col.gameObject == gameObject.transform.parent.gameObject)
{
gameObject.GetComponent<Rigidbody>().AddForce(gameObject.GetComponent<Rigidbody>().linearVelocity * -2, ForceMode.Impulse);
}
}
void OnDisable()
{
}
public override void handleInteraction(GameObject player)
{