public CameraController cameraController; // assign in inspector, or get during runtime in Awake/Start
...
var viewType = cameraController.ActiveViewType;
if (viewType is FirstPerson) {
var firstPerson = (FirstPerson)viewType;
Vector3 lookOffset = firstPerson.LookOffset;
lookOffset.y = 2;
firstPerson.LookOffset = lookOffset;
}
using Opsive.Shared.Events;
using Opsive.Shared.Game;
using Opsive.UltimateCharacterController.Game;
using Opsive.UltimateCharacterController.Inventory;
using Opsive.UltimateCharacterController.Items;
using Opsive.UltimateCharacterController.Motion;
using Opsive.UltimateCharacterController.Utility;
using Opsive.Shared.Camera;
using Opsive.UltimateCharacterController.Camera;
using UnityEngine;
public class HeightChange : MonoBehaviour
{
public CameraController cameraController; // assign in inspector, or get during runtime in Awake/Start
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
var viewType = cameraController.ActiveViewType;
if (viewType is FirstPerson) {
var firstPerson = (FirstPerson)viewType;
Vector3 lookOffset = firstPerson.LookOffset;
lookOffset.y = 2;
firstPerson.LookOffset = lookOffset;
}
}
}
Andrew, please disregard the message above. I place the code under FirstPerson.cs and the error ceased to happen.Noob here.
I want to the following.
if (Input.GetKeyDown(KeyCode.X)) {
// Change the height of the FPS view point to 20.
}
How should I go about it?
void Update()
{
var viewType = cameraController.ActiveViewType;
if (viewType is FirstPerson)
{
var firstPerson = (FirstPerson)viewType;
Vector3 lookOffset = firstPerson.LookOffset;
lookOffset.y = 200;
firstPerson.LookOffset = lookOffset;
}
}
1 - On this custom script what libraries do I need to reference?You can't use an Update loop on a ViewType because it's not a MonoBehaviour. You'd need to use the Update loop on a custom script or another MonoBehaviour script you're using elsewhere
namespace Opsive.UltimateCharacterController.FirstPersonController.Camera.ViewTypes
. So in your own script, you'd need to include Opsive.UltimateCharacterController.FirstPersonController.Camera.ViewTypes;
.