using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace ProceduralToolkit.Examples
{
/// <summary>
/// Simple camera controller
/// </summary>
[RequireComponent(typeof (Image))]
public class CameraRotator : UIBehaviour, IDragHandler
{
public Transform cameraTransform;
public Transform target;
[Header("Position")]
public float distanceMin = 10;
public float distanceMax = 30;
public float yOffset = 0;
public float scrollSensitivity = 1000;
public float scrollSmoothing = 10;
[Header("Rotation")]
public float tiltMin = -85;
public float tiltMax = 85;
public float rotationSensitivity = 0.5f;
public float rotationSpeed = 20;
private float distance;
private float scrollDistance;
private float velocity;
private float lookAngle;
private float tiltAngle;
private Quaternion rotation;
protected override void Awake()
{
base.Awake();
tiltAngle = (tiltMin + tiltMax)/2;
distance = scrollDistance = (distanceMax + distanceMin)/2;
if (cameraTransform == null || target == null) return;
cameraTransform.rotation = rotation = Quaternion.Euler(tiltAngle, lookAngle, 0);
cameraTransform.position = CalculateCameraPosition();
}
private void LateUpdate()
{
if (cameraTransform == null || target == null) return;
if (cameraTransform.rotation != rotation)
{
cameraTransform.rotation = Quaternion.Lerp(cameraTransform.rotation, rotation,
Time.deltaTime*rotationSpeed);
}
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll != 0)
{
scrollDistance -= scroll*Time.deltaTime*scrollSensitivity;
scrollDistance = Mathf.Clamp(scrollDistance, distanceMin, distanceMax);
}
if (distance != scrollDistance)
{
distance = Mathf.SmoothDamp(distance, scrollDistance, ref velocity, Time.deltaTime*scrollSmoothing);
}
cameraTransform.position = CalculateCameraPosition();
}
public void OnDrag(PointerEventData eventData)
{
if (cameraTransform == null || target == null) return;
lookAngle += eventData.delta.x*rotationSensitivity;
tiltAngle -= eventData.delta.y*rotationSensitivity;
tiltAngle = Mathf.Clamp(tiltAngle, tiltMin, tiltMax);
rotation = Quaternion.Euler(tiltAngle, lookAngle, 0);
}
private Vector3 CalculateCameraPosition()
{
return target.position + cameraTransform.rotation*(Vector3.back*distance) + Vector3.up*yOffset;
}
}
}
void Update ()
{
if (Input.GetMouseButton(0))
{
var centerPoint = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight /2, 0);
Ray ray = _camera.ScreenPointToRay(centerPoint);
RaycastHit hit;
bool e = Physics.Raycast(ray, out hit);
if (e)
{
StartCoroutine(SphereIndicator(hit.point));
}
}
}
using UnityEngine;
public class Job : MonoBehaviour
{
public float addmoney;
private void OnTriggerEnter(Collider col)
{
if (col.CompareTag("Box"))
{
PlayerMoney pt = col.GetComponent<PlayerMoney>();
addmoney += pt.money;
}
}
}
using UnityEngine;
public class PlayerMoney : MonoBehaviour
{
public int money;
}
addmoney += pt.money;
using UnityEngine;
public class Moving : MonoBehaviour
{
public float Speed = 0.5f;
private void Update()
{
float horizontal = Input.GetKey(KeyCode.A) ? -Speed : Input.GetKey(KeyCode.D) ? Speed : 0;
float vertical = Input.GetKey(KeyCode.S) ? -Speed : Input.GetKey(KeyCode.W) ? Speed : 0;
transform.Translate(horizontal, 0, vertical);
}
}
MoveScript move = shootTransform.gameObject.GetComponent<MoveScript>();
if (move != null)
{
move.direction = this.transform.right;
}