I am trying to get the particle system to only emit or enable when player is carrying. However when I try to add to my script to enable, it states I cannot not just make a module. I tried using this scripting API, but I come up with the same error.
What I am having problems with and where I am trying to make it work.
In the code below, I am trying to enable the particles on Pickup() and then disable them on Drop(). Also must point out that the player must be close for this to work and assign the particles and gameobject for the player to pickup.
Is there a problem with the API or am I not plugging in my code right? Code:
instead of item = GameObject.FindGameObjectWithTag("Pickups");
don’t you think it should just be item = other; ?
Edit: the above code should have been item = other.gameObject;
You know that FindGameObjectWithTag might return any item that has that tag, where as I assume, you want item to be the item that the play is close to. You don’t need to find it because you already know it must be “other”.
Secondly, why do you enable gravity just because the player is near the item?
The other thing is that just performing a getComponent for AnimalAI doesn’t actually do anything since you’re not using the result.
I didn’t even look at that. I have a similar script that I started with and well, I missed it. Didn’t throw any errors.
I was able to to play around with the code and i think I see the problem or a problem. When I go to pickup I call a bool. When it is true and the mouse button is held down, the object being carried should go to the empty or tempParent.
What I am seeing is, the bool is constantly flashing on and off. If I remove the button and just use the bool in editor, the object does not go to the tempParent and it pushes the player all over the map.
I was able to assign the particles in another script and I am able to turn them on and off.
What I wish to do is pickup and object that will be sent to an empty that is positioned above the head of the player while holding the button down. When I release the object drops in front of the player and the particles stop.
Note: the animals use navmesh agent to wander around and is controlled through the AnimalAI script. I will attach both and a video of what I have.
Not sure, but did you check if Input.GetAxis("Fire1") is actually returning what you expect? It’s usually not a good idea to use == or != on a float value because floats are imprecise.
For Fire1, I would use Input.GetButton("Fire1") instead. It will return “true” if the button is held down, and “false” if it’s not held down. Then you avoid the float comparison altogether.