PlayerMove
Blockmove both reset
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class IceBlockPush : MonoBehaviour
|
||||
{
|
||||
[SerializeField] float contactForce = 2.5f;
|
||||
private Rigidbody rb;
|
||||
[SerializeField] private Vector3 StartPos;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
|
||||
if (other.GetComponent<CapsuleCollider>())
|
||||
{
|
||||
Push(other.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
private void Push(Vector3 position)
|
||||
{
|
||||
Vector3 diffrenceVector = rb.transform.position - position;
|
||||
diffrenceVector.y = 0;
|
||||
//jetzt Vecort auf rechts,links, oben oder unten
|
||||
Vector3 directionVector =
|
||||
Mathf.Abs(diffrenceVector.x) > Mathf.Abs(diffrenceVector.z)
|
||||
? new Vector3(Mathf.Sign(diffrenceVector.x), 0, 0)
|
||||
: new Vector3(0, 0, Mathf.Sign(diffrenceVector.z));
|
||||
|
||||
//Debug.DrawRay(transform.position, directionVector * 3f, Color.red);
|
||||
|
||||
rb.AddForce(directionVector * contactForce, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
this.transform.position = StartPos;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e911d5b3b7fa4494dade3496bff2ee20
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Pit : MonoBehaviour
|
||||
{
|
||||
public PlayerMove player;
|
||||
public IceBlockPush ice;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
player.Reset();
|
||||
ice.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7c1c3fec0605d746bddf36d1b260908
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28852a8ba199cdb458057abc041b9353
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float speed;
|
||||
[SerializeField] private Rigidbody rb;
|
||||
[SerializeField] private Vector3 StartPos;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float horizontalInput = Input.GetAxis("Horizontal");
|
||||
float verticalInput = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 moveDirection = new Vector3(horizontalInput,0, verticalInput);
|
||||
moveDirection.Normalize();
|
||||
|
||||
|
||||
transform.Translate(moveDirection * speed * Time.deltaTime, Space.World);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
this.transform.position = StartPos;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b9bab48a629093449f53dc5ea63d752
|
||||
Reference in New Issue
Block a user