Hi
I have a Monocular Camera at some point the player can use it to see the downtown and zoomin or zoom out while dragging a handle on a 0-1 straightTrack.
I tried to make it but i get errors shoiwng
using UnityEngine;
using AC;
public class ZoomControl : MonoBehaviour
{
// The name of the global variable in Adventure Creator
public string zoomVariableName = "Zoom";
// The minimum and maximum values for the draggable object's position
public float minPosition = 0f;
public float maxPosition = 1f;
// The camera whose FoV will be affected
public Camera gameCamera;
// The minimum and maximum field of view values for the camera
public float minFOV = 25f;
public float maxFOV = 55f;
// Update is called once per frame
private void Update()
{
// Get the current position of the draggable object
float currentPosition = Mathf.Clamp01(GetObjectPosition());
// Update the global variable in Adventure Creator
SetGlobalVariable(zoomVariableName, currentPosition);
// Update the camera's FoV based on the global variable
float newFOV = Mathf.Lerp(minFOV, maxFOV, currentPosition);
gameCamera.fieldOfView = newFOV;
}
// Get normalized position of the draggable object between minPosition and maxPosition
private float GetObjectPosition()
{
float objectPosition = Mathf.InverseLerp(minPosition, maxPosition, transform.localPosition.x);
return Mathf.Clamp01(objectPosition);
}
// Helper to set the value of a global variable in AC
private void SetGlobalVariable(string variableName, float value)
{
GVar globalVariable = GlobalVariables.GetVariable(variableName);
// value based on the type of the global variable
if (globalVariable.type == VariableType.Float)
{
globalVariable.floatVal = value;
}
else if (globalVariable.type == VariableType.String)
{
globalVariable.textVal = value.ToString();
}
}
}
I get errors Like :
error CS0122: 'GVar.floatVal' is inaccessible due to its protection level
also about GVar.TextVal the same
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I forgot to mention:
Unity 2020.3.30f1 with ACv1.79.1 in a 3D direct game.
I was Also thinking maybe i must Make an Animation for my Camera with FoV change and try using draggable position of Track to control which frame it must show ?!
Alternatively I just made 4 animations for MonocularCamera to have FoV changes, then used OnRelease action list of the Draggable.
apparently it is not as juicy as the other way which was thinking about. Lack of programming knowledge
Use FloatValue and TextValue instead of floatVal and textVal.
Yes, you could create a Blend Tree and use a parameter that goes from 0 -> 1 to control it. You can get how far along a Draggable is along its track with the GetPositionAlong function.
Thanks Chris! It solved my main problem and helps me learn alot.
Here is the code which is working fine.(In case somebody needs such behavior)
Ah! Blend tree which i forgot due to my lack of experience was even a more neat way to do it! thanks for insights.