MOD: Meine Testszene bearbeitet
ADD: temp. Player Movement script
This commit is contained in:
8
ProjektUnity/Assets/Scripts/Player.meta
Normal file
8
ProjektUnity/Assets/Scripts/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c25df2829fc139488b9e362d562e925
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
ProjektUnity/Assets/Scripts/Player/PlayerMover.cs
Normal file
48
ProjektUnity/Assets/Scripts/Player/PlayerMover.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMover : MonoBehaviour
|
||||
{
|
||||
public KeyCode up = KeyCode.W;
|
||||
public KeyCode down = KeyCode.S;
|
||||
public KeyCode left = KeyCode.A;
|
||||
public KeyCode right = KeyCode.D;
|
||||
|
||||
public Rigidbody2D rb;
|
||||
public float speed = 2f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Move();
|
||||
}
|
||||
|
||||
public void Move(){
|
||||
Vector2 moveDirection = Vector2.zero;
|
||||
if(Input.GetKey(up)){
|
||||
moveDirection += Vector2.up;
|
||||
}
|
||||
if(Input.GetKey(down)){
|
||||
moveDirection += Vector2.down;
|
||||
}
|
||||
if(Input.GetKey(left)){
|
||||
moveDirection += Vector2.left;
|
||||
}
|
||||
if(Input.GetKey(right)){
|
||||
moveDirection += Vector2.right;
|
||||
}
|
||||
|
||||
if(moveDirection.magnitude > 1){
|
||||
moveDirection.Normalize();
|
||||
}
|
||||
|
||||
rb.velocity = moveDirection * speed;
|
||||
}
|
||||
}
|
11
ProjektUnity/Assets/Scripts/Player/PlayerMover.cs.meta
Normal file
11
ProjektUnity/Assets/Scripts/Player/PlayerMover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f45bbb18d60cef43a7ea83eb723f2f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user