Skip to content
Snippets Groups Projects
Commit ef5aef70 authored by Viktor Palmason's avatar Viktor Palmason
Browse files

Implemented a point system where the player gets points by defeating a enemy #2

parent a0bbe305
No related branches found
No related tags found
1 merge request!1Viktor develop into master
No preview for this file type
......@@ -12,8 +12,16 @@ public class Enemy : MonoBehaviour
[SerializeField] private Vector3 _endPos;
[SerializeField] [Range(0f, 1f)] private float _fraction = 0.5f;
private PlayerControler _player;
private void Start()
{
_player = GameObject.Find("Male A").GetComponent<PlayerControler>();
if(_player == null)
{
Debug.LogError("Player is NULL");
}
_beginPos = transform.position + Vector3.left;
_endPos = transform.position + Vector3.right;
}
......@@ -32,6 +40,7 @@ public class Enemy : MonoBehaviour
/*float randomXPos = Random.Range(-9f, 9f);
Vector3 posToSpawn = new Vector3(randomXPos, 1.6f, 0f);
transform.position = posToSpawn;*/
_player.GivePlayerPoints();
Destroy(this.gameObject);
}
}
......
......@@ -14,6 +14,8 @@ public class PlayerControler : MonoBehaviour
private Vector3 _movementDirection;
private Quaternion _right, _left;
[SerializeField] private int _score = 0;
//Animator animator;
private void Start()
......@@ -84,13 +86,18 @@ public class PlayerControler : MonoBehaviour
private void FixedUpdate()
{
moveCharacter();
MoveCharacter();
}
private void moveCharacter()
private void MoveCharacter()
{
_movementDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
_rb.MovePosition(transform.position + (_movementDirection * _movementSpeed * Time.deltaTime));
}
public void GivePlayerPoints()
{
_score += 10;
}
}
No preview for this file type
No preview for this file type
No preview for this file type
Base path: 'D:/Program Files/Unity/Hub/Editor/2020.1.9f1/Editor/Data', plugins path 'D:/Program Files/Unity/Hub/Editor/2020.1.9f1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment