Hello
i use for my private example for mobile your spineboy. With joystick the boy can run and jump. i shoot, the boons and the bullet follow the touch.
After using the joystick the shooting is only horizontal , not in the touch direction. BeginnerInput for touching and the BeginnerView for shooting.
public class SpineboyBeginnerInput
public void OnValidate()
{
if (skeletonAnimation == null) skeletonAnimation = GetComponent<SkeletonAnimation>();
if (model == null) model = GetComponent<SpineboyBeginnerModel>();
}
#endregion
private void Start()
{
rb = GetComponent<Rigidbody2D>();
//myScreenPos = Camera.main.WorldToScreenPoint(this.transform.position);
}
public void FixedUpdate()
{
rb.MovePosition(rb.position + move * speed * Time.fixedDeltaTime);
}
public void Update()
{
//Debug.Log("Target_update");
if (model == null) return;
float currentHorizontal = Input.GetAxisRaw(horizontalAxis);
currentHorizontal = joystick.Horizontal;
model.TryMove(currentHorizontal);
//if (Input.GetButton(attackButton))
if (Input.touchCount > 0)
{
//Debug.Log("Input: Touch - " + Input.touchCount);
touch = Input.GetTouch(0);
}
else { return; }
if (Input.touchCount < 0 || touch.phase != TouchPhase.Began)
{ return;
}
if (IsPointerOverGameObject())
{
//Debug.Log("Input: Touch Over UI " + Input.touchCount);
}
else
{
model.TryShoot();
}
if (Input.GetButtonDown(jumpButton))
model.TryJump();
}
public bool IsPointerOverGameObject()
{
if (EventSystem.current.IsPointerOverGameObject())
{
return true;
}
// Check touches
for (int i = 0; i < Input.touchCount; i++)
{
var touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began)
{
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
return true;
}
}
}
return false;
}
}
}
a part from public class SpineboyBeginnerView
public void PlayShoot()
{
// Play the shoot animation on track 1.
var shootTrack = skeletonAnimation.AnimationState.SetAnimation(1, shoot, false);
Debug.Log("PlayShoot: Shooting");
shootTrack.AttachmentThreshold = 1f;
shootTrack.MixDuration = 0f;
var empty1 = skeletonAnimation.state.AddEmptyAnimation(1, 0.5f, 0.1f);
empty1.AttachmentThreshold = 1f;
// Play the aim animation on track 2 to aim at the mouse target.
var aimTrack = skeletonAnimation.AnimationState.SetAnimation(2, aim, false);
aimTrack.AttachmentThreshold = 1f;
aimTrack.MixDuration = 0f;
var empty2 = skeletonAnimation.state.AddEmptyAnimation(2, 0.5f, 0.1f);
empty2.AttachmentThreshold = 1f;
gunSource.pitch = GetRandomPitch(gunsoundPitchOffset);
gunSource.Play();
}