Implemented a movement controller.
This commit is contained in:
8
Assets/script/movement.meta
Normal file
8
Assets/script/movement.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 950cc6d2bbff5bc4f9439caba4f5ed96
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/script/movement/Bullet.cs
Normal file
19
Assets/script/movement/Bullet.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Bullet : MonoBehaviour
|
||||
{
|
||||
Rigidbody2D rb;
|
||||
public float damage;
|
||||
public float time = 2f;
|
||||
|
||||
public void ApplyVel(Vector2 dir,float speed) {
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = dir * speed;
|
||||
Destroy(gameObject, time);
|
||||
}
|
||||
private void OnCollisionEnter2D(Collision2D c) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
11
Assets/script/movement/Bullet.cs.meta
Normal file
11
Assets/script/movement/Bullet.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d44ecfac57ea864390136ef706f6ad3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/script/movement/PlayerController.cs
Normal file
38
Assets/script/movement/PlayerController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
|
||||
public class PlayerController : MonoBehaviour {
|
||||
Vector3 direction;
|
||||
public float speed;
|
||||
#if tmp
|
||||
public GameObject bullet;
|
||||
#endif
|
||||
AudioSource aus;
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
aus = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
//direction = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
|
||||
gameObject.transform.position += Vector3.Normalize(new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0))*0.25f;
|
||||
/*if(Input.GetButtonDown("Fire1")) {
|
||||
Vector3 offset = transform.position + new Vector3(lastDirection.x+0.1f, lastDirection.y+0.1f, 0f);
|
||||
aus.Play();
|
||||
GameObject.Instantiate(bullet, offset, Quaternion.identity);
|
||||
}*/
|
||||
}
|
||||
|
||||
/*private void FixedUpdate() {
|
||||
gameObject.transform.position += Vector3.Normalize(direction)*0.1f;
|
||||
}*/
|
||||
public void Move(InputValue v) {
|
||||
var m = v.Get<Vector2>();
|
||||
gameObject.transform.position = new Vector3(m.x, m.y, 0f);
|
||||
}
|
||||
}
|
||||
13
Assets/script/movement/PlayerController.cs.meta
Normal file
13
Assets/script/movement/PlayerController.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c9d76b1e7bbf2d498eca3de6f5f8d08
|
||||
labels:
|
||||
- 2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user