- Home /
Pikmin Thrown one at a time
hello I am making a pikmin fan game and I am trying to make it so that I can throw the pikmin, I used DoTween to DoJump the pikmin from their origin point to the cursor position but the problem I am facing is that since every pikmin is a duplicate they all jump to the same position at the same time. I want to make it so taht they have a type of order to them and that they are thrown in that order. Here is my code (its pretty messy) :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using DG.Tweening;
public class Pikmin : MonoBehaviour {
public bool grabbed;
public int entitynum;
public Transform whistle;
public Vector3 target;
public Transform player;
public Vector3 grab;
public float time;
public float delay;
//public Collider planecollider;
public bool idle;
public bool isThrowable;
public NavMeshAgent agent;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Whistle" && Input.GetButton("Fire2"))
{
idle = false;
}
if (other.gameObject.tag == "Throwable")
{
Debug.Log("with in throwing range");
isThrowable = true;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Throwable")
{
Debug.Log("with in throwing range");
isThrowable = false;
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player")
{
Debug.Log("following");
idle = false;
}
}
void Start()
{
}
void FixedUpdate()
{
target = whistle.transform.position;
grab = player.transform.position;
}
private void Update()
{
if (Input.GetButtonUp("Fire1") && isThrowable == true )
{
transform.DOJump(target, 2, 1, time).SetDelay(delay).SetEase(Ease.Linear);
isThrowable = false;
grabbed = false;
}
if (grabbed)
{
transform.position = grab;
}
if (Input.GetButtonDown("Fire1") && idle == false && isThrowable == true)
{
idle = true;
grabbed = true;
}
agent = GetComponent<NavMeshAgent>();
if (Input.GetButtonUp("LShift"))
{
idle = true;
}
if (idle == true)
{
agent.enabled = false;
}
if (idle == false)
{
agent.enabled = true;
}
}
}
Your answer
Follow this Question
Related Questions
Canvas with GUI elements in prefab act strangely 0 Answers
How to make On Click() work with prefabs? 1 Answer
Changing the Material of an instance of a prefab only! 2 Answers
Trigger resets to 1-1-1 scale automatically. (Not supposed to) 0 Answers
Text Not Being Displayed above Instantiated Prefabs 0 Answers