1
LoadSceneonClick.js
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadSceneOnClick : MonoBehaviour {
public void LoadByIndex(int sceneIndex) {
SceneManager.LoadScene(sceneIndex);
} }
showPanel.js
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine.UI;
public class panelscript : MonoBehaviour {
public GameObject Panel; public void showPanel()
{
Panel.gameObject.SetActive (true); }
}
hidePanel.js
using System.Collections;
using System.Collections.Generic;
public class panelscript : MonoBehaviour {
public GameObject Panel; public void hidePanel()
{
Panel.gameObject.SetActive (false); }
}
Motor.js
using UnityEngine;
using System.Collections;
public class Motor : MonoBehaviour
{
public float moveSpeed = 5.0f; public float drag = 0.5f;
public float terminalRotationSpeed = 25.0f; public VirtualJoystick moveJoystick;
private Rigidbody controller; private Transform camTransform;
private void Start ()
{
controller = GetComponent<Rigidbody> ();
controller.maxAngularVelocity = terminalRotationSpeed;
controller.drag = drag;
camTransform = Camera.main.transform; }
private void Update() {
Vector3 dir = Vector3.zero;
dir.x = Input.GetAxis ("Horizontal");
dir.z = Input.GetAxis ("Vertical");
if (dir.magnitude > 1) dir.Normalize ();
3
{
dir = moveJoystick.InputDirection;
}
Vector3 rotatedDir = camTransform.TransformDirection (dir); rotatedDir = new Vector3 (rotatedDir.x, 0, rotatedDir.z); rotatedDir = rotatedDir.normalized * dir.magnitude;
controller.AddForce (rotatedDir * moveSpeed);
} }
CameraMotor.js
using UnityEngine;using System.Collections;
public class CameraMotor : MonoBehaviour
{
public Transform lookAt;
private Vector3 desiredPosition; private Vector3 offset;
private float smoothSpeed = 7.5f;
private float distance = 5.0f; private float yOffset = 3.5f;
private void Start() {
offset = new Vector3 (0, yOffset, -1f * distance); }
private void Update() {
if (Input.GetKeyDown (KeyCode.LeftArrow)) SlideCamera (true);
else if (Input.GetKeyDown (KeyCode.RightArrow))
SlideCamera (false);
desiredPosition = lookAt.position + offset;
transform.position = Vector3.Lerp (transform.position,
}
private void SlideCamera(bool left) {
if (left)
offset = Quaternion.Euler (0, 90, 0) * offset;
else
offset = Quaternion.Euler (0, -90, 0) * offset;
} }
VirtualJoystick.js
using UnityEngine;using UnityEngine.UI;
using UnityEngine.EventSystems; using System.Collections;
public class VirtualJoystick : MonoBehaviour, IDragHandler,
IPointerUpHandler, IPointerDownHandler {
private Image bgImg;
private Image joystickImg;
public Vector3 InputDirection { set; get;}
private void Start()
{
bgImg = GetComponent<Image> ();
joystickImg = transform.GetChild(0).GetComponent<Image> (); InputDirection = Vector3.zero;
}
public virtual void OnDrag(PointerEventData ped)
{
Vector2 pos = Vector2.zero;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle
(bgImg.rectTransform, ped.position,
ped.pressEventCamera, out pos))
{
5
pos.y = (pos.y / bgImg.rectTransform.sizeDelta.y);
float x = (bgImg.rectTransform.pivot.x == 1) ? pos.x * 2 + 1 : pos.x * 2 - 1;
float y = (bgImg.rectTransform.pivot.y == 1) ? pos.y * 2 + 1 : pos.y * 2 - 1;
InputDirection = new Vector3 (x, 0, y);
InputDirection = (InputDirection.magnitude > 1) ?
InputDirection.normalized : InputDirection;
joystickImg.rectTransform.anchoredPosition =
new Vector3
(InputDirection.x*(bgImg.rectTransform.sizeDelta.x / 3)
, InputDirection.z * (bgImg.rectTransform.sizeDelta.y / 3));
} }
public virtual void OnPointerDown(PointerEventData ped) {
OnDrag (ped); }
public virtual void OnPointerUp(PointerEventData ped) {
InputDirection = Vector3.zero;
joystickImg.rectTransform.anchoredPosition = Vector3.zero;
} }
QuitonClick.js
using System.Collections;
using UnityEngine;
public class QuitOnClick : MonoBehaviour {
public void Quit ()
{
#if UNITY_EDITOR
#else
Application.Quit();
#endif