Hi. I'm having trouble with weapon pick up .I made so far when i collide with weapon collider it shows GUI , and it gets WeaponIndex from that picked up weapon , and adds it to this script.But it won't work i don't know why. 1) It won't detect collision 2) How to add weapon number from weapon that i picked up to my pick up script. Script is : PickUP Code (csharp): var ShowGUI : boolean = false; var PickUpE : Texture2D; var script : WeaponIndex; var Index : int = 0; var curWeapon : int = 0; //******1)******* //It won't detect collision between Character and weapon function OnCollisionEnter (collide : Collider) { if(collide.gameObject.tag == "Weapons") { //*****2)****** //How to add WpIndex number to Index number that i have in this script script.GetComponent("WeaponIndex").WpIndex = Index; ShowGUI = true; } } function OnCollisionExit(isExitCollide : Collision) { ShowGUI = false; } function OnGUI() { if(ShowGUI) { GUI.DrawTexture(Rect(85,30,100,20), PickUpE); } } I used simple for Weapon Index. WeaponIndex Code (csharp): //Weapon Number var WpIndex : int = 0; Anybody knows how to solve this. Thanx for your time and help. -3DK
Hey! Code doesn't make much sense to me. 1.What object is it attached to? 2.Why don't you make any reference to the actual WeaponIndex? when you say Code (csharp): var script : WeaponIndex; and then Code (csharp): script.GetComponent("WeaponIndex").WpIndex = Index; aren't you getting the same component you're refering to? If I were you, I'd reference the var script to the weaponindex script of the player, and then change it's value. Bear in mind it's a reference value, so it's not copied but pointed to when you do this: [CODE script = GetComponent("WeaponIndex"); script.WpIndex = Index; [/CODE] This would be using your actual code. I think there are less convoluted ways of doing this . Happy coding!
from the help page for OnCollisionEnter You don't mention either the weapon or the char having a rigidbody...
Hi, thanks for reply. I attached(WeaponPickUp Script) to my Player (Capsule) which has Character Controller . And the weapon that i want to collide with has rigidbody (Use Gravity checked , Is Kinematic unchecked). I'm sorry if i didn't make it more clearly You see i wanted when my character hits Gun(That has Rigidbody) it gets that weapons index number.So i can use that number to activate(disabled) weapon. Something like : Code (csharp): if(curWeapon == 1) { MainWep = WpIndex; } if (WpIndex == 1 ) { Weapon1 = True; AllOtherWp = false; } Or if you know a better way to pick up weapons. Something like that i don't really know i just made it. I hope it's more understanding Thanx for time