I am making an fps game as a school assignment, and I made an ammobox, medicbox and waterbottle, that are objects that can be picked up, you can probably already guess what they do.
Medicbox: dissapears after picking up and gives health
Ammobox: dissapears after picking up and adds ammo
Waterbottle: dissapears after picking up and gives health + speed.
The problem is, I created medicbox and ammobox, everything worked fine, then I created the water bottle and suddenly I can’t pick up the medicbox/ammobox anymore. The triggering function oes not work for these 2 (when they did before ) I did not change any coding for them. They have the same code as the waterbottle, but the waterbottle CAN be picked up…
Can you guys tell me what I did wrong please?
note: I’ve updated other.gameObject.name == “firstAid” into “FirstAid” , so it matches the name, that did not fix it.
you’ve got some typos in the firstaid thing. You’ve named the mesh “FirstAdd” and in your script, you’re checking for “firstAid” (lowercase f) whereas it has an uppercase on the object.
I don’t know if either of these will solve your problem, but go fix them anyway, and then test again
Yes I was working on that right after I post this, this is my code for them now, still doesn’t work
MEDICBOX:
public class MedicBoxInScene : MonoBehaviour {
public string thingToAdd = "currentValue";
public int amountToAdd = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
Debug.Log("I'm triggerd");
if (other.gameObject.tag == "Player")
{
GameObject.Find("Player").GetComponent<myInventory>().CreateMedicBox(thingToAdd, amountToAdd);
Destroy(gameObject);
}
}
}
WATERBOTTLE:
public class WaterBottleInScene : MonoBehaviour {
public string thingToAdd = "currentValue";
public int amountToAdd = 20;
public int doubleIt = 2;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
GameObject.Find("Player").GetComponent<myInventory>().CreateWaterBottle(doubleIt, thingToAdd, amountToAdd);
Destroy(gameObject);
}
}
}
Just added my script, the medicbox script, to another object, (baseballbat) and he picks that up… and runs the script, so I’m thinking the problem lies in the object, but how can an object be broken… lol…
i’m looking at your scene now. How exactly have you been testing things? there doesnt seem to be any kind of input or camera system implemented, play mode is basically functionless. I’ll try dropping objects on the character anyway.
Well i found what’s wrong. Pretty much everything lol. Are you sure this is the project you’ve been testing with?
The most notable problems
-The player has no collider
-the player isn’t tagged player (or any tag)
-the waterbottle, medkit and ammobox have no scripts on them.
I scripted them all with a debug message in onTriggerEnter, stuck a capsule collider on your player, and moved them through him. they all trigger just fine.
I have no idea what you’ve been doing, it looks like you’ve just deleted all the work and given me bare assets.
Uhm I don’t know what you got, but when I send my zipped files to my group partner, he can just open it and play the same way I did… I think there must’ve gone something wrong… really weird, my partner can always open the stuff I send him