Dimensionsshift added und Character Controller in Script Ordner
verschoben
This commit is contained in:
99
Assets/AssetsFORELLE/Script/CharController.cs
Normal file
99
Assets/AssetsFORELLE/Script/CharController.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharController : MonoBehaviour
|
||||
{
|
||||
|
||||
public float maxSpeed = 3.4f;
|
||||
public float jumpHeight = 6.5f;
|
||||
public float gravityScale = 1.5f;
|
||||
public Camera mainCamera;
|
||||
|
||||
|
||||
bool facingRight = true;
|
||||
public bool grounded = false;
|
||||
Vector3 cameraPos;
|
||||
float moveDirection = 0;
|
||||
Rigidbody2D rb;
|
||||
CapsuleCollider2D mainCollider;
|
||||
CapsuleCollider2D friction;
|
||||
Transform t;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
t = transform;
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
mainCollider = GetComponent<CapsuleCollider2D>();
|
||||
friction = GetComponent<CapsuleCollider2D>();
|
||||
rb.freezeRotation = true;
|
||||
rb.gravityScale = gravityScale;
|
||||
|
||||
if(mainCamera)
|
||||
{
|
||||
cameraPos = mainCamera.transform.position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
//if(grounded || Mathf.Abs(rb.velocity.x) > 0.01f)
|
||||
moveDirection = Input.GetAxisRaw("Horizontal");
|
||||
|
||||
if(moveDirection != 0)
|
||||
{
|
||||
if (moveDirection > 0 && !facingRight)
|
||||
{
|
||||
facingRight = true;
|
||||
t.localScale = new Vector3(Mathf.Abs(t.localScale.x), t.localScale.y, transform.localScale.z);
|
||||
}
|
||||
if (moveDirection < 0 && facingRight)
|
||||
{
|
||||
facingRight = false;
|
||||
t.localScale = new Vector3(-Mathf.Abs(t.localScale.x), t.localScale.y, t.localScale.z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(Input.GetButtonDown("Jump") && grounded)
|
||||
{
|
||||
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
|
||||
}
|
||||
|
||||
if (mainCamera)
|
||||
{
|
||||
mainCamera.transform.position = new Vector3(t.position.x, cameraPos.y, cameraPos.z);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
|
||||
Bounds colliderBounds = mainCollider.bounds;
|
||||
float colliderRadius = mainCollider.size.x * 0.4f * Mathf.Abs(transform.localScale.x);
|
||||
Vector3 groundCheckPos = colliderBounds.min + new Vector3(colliderBounds.size.x * 0.5f, colliderRadius * 0.9f, 0);
|
||||
|
||||
Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheckPos, colliderRadius);
|
||||
|
||||
grounded = false;
|
||||
if (colliders.Length > 2)
|
||||
{
|
||||
foreach (Collider2D hit in colliders){
|
||||
if (hit != mainCollider){
|
||||
grounded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rb.velocity = new Vector2(moveDirection * maxSpeed, rb.velocity.y);
|
||||
|
||||
Debug.DrawLine(groundCheckPos, groundCheckPos - new Vector3(0, colliderRadius, 0), grounded ? Color.green : Color.red);
|
||||
Debug.DrawLine(groundCheckPos, groundCheckPos - new Vector3(colliderRadius, 0, 0), grounded ? Color.green : Color.red);
|
||||
}
|
||||
}
|
||||
11
Assets/AssetsFORELLE/Script/CharController.cs.meta
generated
Normal file
11
Assets/AssetsFORELLE/Script/CharController.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57eab097b9fc58c4c88a5c9ba60e9c64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/AssetsFORELLE/Script/DimShift.cs
Normal file
47
Assets/AssetsFORELLE/Script/DimShift.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// Kann sein das das nur für statische Objekte funktioniert
|
||||
public class DimShift : MonoBehaviour
|
||||
{
|
||||
// 0 = inactive in Dimension 1
|
||||
// 1 = active in Dimension 1
|
||||
public bool inFirstDim;
|
||||
BoxCollider2D col;
|
||||
SpriteRenderer rend;
|
||||
void Start()
|
||||
{
|
||||
col = GetComponent<BoxCollider2D>();
|
||||
rend = GetComponent<SpriteRenderer>();
|
||||
|
||||
if (inFirstDim)
|
||||
{
|
||||
col.enabled = true;
|
||||
rend.enabled = true;
|
||||
|
||||
} else
|
||||
{
|
||||
col.enabled = false;
|
||||
rend.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftShift)&&inFirstDim)
|
||||
{
|
||||
col.enabled = false;
|
||||
rend.enabled = false;
|
||||
inFirstDim = !inFirstDim;
|
||||
} else
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftShift)&&!inFirstDim)
|
||||
{
|
||||
col.enabled = true;
|
||||
rend.enabled = true;
|
||||
inFirstDim = !inFirstDim;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/AssetsFORELLE/Script/DimShift.cs.meta
generated
Normal file
11
Assets/AssetsFORELLE/Script/DimShift.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef524aa2ad305d4faf6b90a610e5be4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user