Hi,
I have a first person scene with a UFPS character and want to change the 'disable free-aim when moving Draggables and PickUps' on runtime depending on the type of object the player is currently moving
To be more specific, I want to have it enabled for Draggable objects but have it disabled for PickUp objects.
After looking in the manual and some threads in here my understanding is that I can change this setting by using AC.KickStarter.settingsManager.disableFreeAimWhenDragging through a custom script.
I know that probably this is very simple but since my scripting knowledge is limited I don't know exactly how to use this and was hoping that someone could help me.
Thanks
Comments
Indeed, that's the correct setting to change through script. What you'll want to do is make use of the OnGrabMoveable custom event. Custom events are a way of hooking custom code up to common AC events - in this case, when a moveable object is grabbed. More on custom events can be found in this tutorial as well as the Manual.
This ought to do it. Paste the following in a C# script named MoveableEventTest, and attach it to a GameObject in your scene:
using UnityEngine;
using System.Collections;
using AC;
public class MoveableEventTest : MonoBehaviour
{
private void OnEnable ()
{
EventManager.OnGrabMoveable += GrabMoveable;
}
private void OnDisable ()
{
EventManager.OnGrabMoveable -= GrabMoveable;
}
private void GrabMoveable (DragBase dragBase)
{
Debug.Log ("Grabbed: " + dragBase.name);
if (dragBase is PickUp)
{
AC.KickStarter.settingsManager.disableFreeAimWhenDragging = false;
}
else
{
AC.KickStarter.settingsManager.disableFreeAimWhenDragging = true;
}
}
}
One small correction in case anyone else wants to use this.
I was getting a namespace not found in line : "if (dragBase is PickUp)"
I changed "PickUp" to "Moveable_PickUp" and it works just fine.
I was thinking of a way more complex way of doing this so your help is very much appreciated. I guess it's time for me to study custom events a bit more.
Once again thanks for your time and for making such a great tool.