SHADE_Y3/Assets/Scripts/ThirdPersonCamera.cs

61 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
namespace SHADE_Scripting
{
public class ThirdPersonCamera: Script
{
public float armLength = 2.0f;
public float turnSpeedPitch = 0.3f;
public float turnSpeedYaw = 0.5f;
public float pitchClamp = 45.0f;
protected override void awake()
{
AddComponent<Transform>();
if(!GetComponent<Camera>())
{
AddComponent<Camera>();
}
GetComponent<Camera>().SetMainCamera();
if (!GetComponent<CameraArm>())
{
AddComponent<CameraArm>();
}
GetComponent<CameraArm>().ArmLength = armLength;
}
protected override void update()
{
if (Input.GetMouseButton(Input.MouseCode.RightButton))
{
CameraArm arm = GetComponent<CameraArm>();
if (arm)
{
Vector2 vel = Input.GetMouseVelocity();
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF;
if (arm.Pitch > pitchClamp)
{
arm.Pitch = pitchClamp;
}
else if (arm.Pitch < 0)
{
arm.Pitch = 0;
}
}
}
}
}
}