<commit_before>﻿using System;
using UnityEngine;

public class Unit : WorldObject {
	public float moveSpeed = 10;
	public float rotationSpeed = 180;
	public GameObject pathVisualPrefab;

	bool moving;
	Vector3 targetPosition;
	Quaternion targetRotation;

	GameObject pathVisual;
	GameObject targetVisual;

	void Update () {
		if (moving) {
			Move ();
			Rotate ();

			if (Selected) {
				UpdatePathVisual ();
			}
		}
	}

	public override void SetSelected(bool selected) {
		base.SetSelected (selected);

		if (selected) {
			if (moving) {
				AddPathVisual ();
			}
		} else {
			RemovePathVisual ();
		}
	}

	void Move () {
		transform.position = Vector3.MoveTowards (transform.position, targetPosition, moveSpeed * Time.deltaTime);

		if (transform.position == targetPosition) {
			moving = false;
			RemovePathVisual ();
		}
	}

	void Rotate () {
		transform.rotation = Quaternion.RotateTowards (transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
	}

	public override void HandleRightClick (Vector3 position, WorldObject hitObject) {
		Debug.Log ("RIGHT CLICK");
		var navMeshAgent = GetComponent<NavMeshAgent> ();
		if (navMeshAgent) {
			navMeshAgent.destination = targetPosition;
		} else {
			moving = true;
			targetPosition = position;
			targetRotation = Quaternion.LookRotation (targetPosition - transform.position);


			AddPathVisual ();
		}
	}

	void AddPathVisual() {
		if (pathVisual) {
			RemovePathVisual ();
		}

		targetVisual = GameObject.CreatePrimitive (PrimitiveType.Sphere);
		targetVisual.GetComponent<MeshRenderer> ().material.color = Color.blue;
		targetVisual.transform.position = targetPosition;
		targetVisual.transform.localScale = Vector3.one * 4;
		targetVisual.GetComponent<Collider> ().enabled = false;

		//pathVisual = (GameObject)Instantiate (pathVisualPrefab);
		pathVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);
		pathVisual.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.red;
		pathVisual.transform.SetParent (transform);
		Vector3 pos = transform.position;
		pos.y = 0.1f;
		pathVisual.transform.position = pos;
		pathVisual.transform.rotation = transform.rotation * Quaternion.Euler(0, 90f, 0);
	}

	void UpdatePathVisual() {
		pathVisual.transform.rotation = transform.rotation * Quaternion.Euler(0, 90f, 0);

		Vector3 direction = targetPosition - transform.position;
		float distance = direction.magnitude;
		pathVisual.transform.position = transform.position + (targetPosition-transform.position)/2f;
		pathVisual.transform.localScale = new Vector3 (distance / 6, 1, 1);
	}

	void RemovePathVisual() {
		if (pathVisual) {
			Destroy (pathVisual);
			pathVisual = null;
		}

		if (targetVisual) {
			Destroy (targetVisual);<commit_msg>reset y on update<commit_after>﻿using System;
using UnityEngine;

public class Unit : WorldObject {
	public float moveSpeed = 10;
	public float rotationSpeed = 180;
	public GameObject pathVisualPrefab;

	bool moving;
	Vector3 targetPosition;
	Quaternion targetRotation;

	GameObject pathVisual;
	GameObject targetVisual;

	void Update () {
		if (moving) {
			Move ();
			Rotate ();

			if (Selected) {
				UpdatePathVisual ();
			}
		}
	}

	public override void SetSelected(bool selected) {
		base.SetSelected (selected);

		if (selected) {
			if (moving) {
				AddPathVisual ();
			}
		} else {
			RemovePathVisual ();
		}
	}

	void Move () {
		transform.position = Vector3.MoveTowards (transform.position, targetPosition, moveSpeed * Time.deltaTime);

		if (transform.position == targetPosition) {
			moving = false;
			RemovePathVisual ();
		}
	}

	void Rotate () {
		transform.rotation = Quaternion.RotateTowards (transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
	}

	public override void HandleRightClick (Vector3 position, WorldObject hitObject) {
		Debug.Log ("RIGHT CLICK");
		var navMeshAgent = GetComponent<NavMeshAgent> ();
		if (navMeshAgent) {
			navMeshAgent.destination = targetPosition;
		} else {
			moving = true;
			targetPosition = position;
			targetRotation = Quaternion.LookRotation (targetPosition - transform.position);


			AddPathVisual ();
		}
	}

	void AddPathVisual() {
		if (pathVisual) {
			RemovePathVisual ();
		}

		targetVisual = GameObject.CreatePrimitive (PrimitiveType.Sphere);
		targetVisual.GetComponent<MeshRenderer> ().material.color = Color.blue;
		targetVisual.transform.position = targetPosition;
		targetVisual.transform.localScale = Vector3.one * 4;
		targetVisual.GetComponent<Collider> ().enabled = false;

		//pathVisual = (GameObject)Instantiate (pathVisualPrefab);
		pathVisual = GameObject.CreatePrimitive(PrimitiveType.Cube);
		pathVisual.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.red;
		pathVisual.GetComponent<Collider> ().enabled = false;
		pathVisual.transform.SetParent (transform);
		Vector3 pos = transform.position;
		pos.y = 0.1f;
		pathVisual.transform.position = pos;
	}

	void UpdatePathVisual() {
		pathVisual.transform.rotation = transform.rotation * Quaternion.Euler(0, 90f, 0);

		Vector3 direction = targetPosition - transform.position;
		float distance = direction.magnitude;
		Vector3 pos = transform.position + (targetPosition-transform.position)/2f;
		pos.y = 0.1f;
		pathVisual.transform.position = pos;
		pathVisual.transform.localScale = new Vector3 (distance / 6, 1, 1);
	}

	void RemovePathVisual() {
		if (pathVisual) {
			Destroy (pathVisual);
			pathVisual = null;
		}

		if (targetVisual) {
			Destroy (targetVisual);
{'fraction_non_alphanumeric': 0.11070448307410796, 'fraction_numerical': 0.00969807868252516, 'mean_word_length': 4.296511627906977, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2604365', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1627, 'n_words': 363}