Okey, i created some scripts to create an FPS with an Axe there are the scripts:
ItemPickupSystem
#pragma strict
var canHover : boolean = false;
var width = 100;
var height = 100;
var width2 = 100;
var height2 = 100;
private var itemScript : ItemScript;
private var Name : String;
var handTexture : Texture;
//Items variables
var axeInHands = false;
var somethingInHands : boolean = false;
//
public var pickupLayers : LayerMask;
private var heldObject : GameObject = null;
function Update(){
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2,Screen.height/2,0));
var rayHit : RaycastHit;
if(Physics.SphereCast(ray, 0.2, rayHit, 4, pickupLayers)){
canHover = true;
itemScript = rayHit.collider.gameObject.GetComponent(ItemScript);
Name = itemScript.itemName;
if(Input.GetButtonDown("Interact")){
// Do the axe variable
if(rayHit.collider.gameObject.GetComponent(AxeScript) != null){
axeInHands = true;
somethingInHands = true;
}else{
axeInHands = false;
somethingInHands = false;
}
}
}else{
canHover = false;
}
//Drop system
if(somethingInHands && Input.GetButtonDown("Drop")){
axeInHands = false;
somethingInHands = false;
}
}
function OnGUI(){
if(canHover && !axeInHands){
GUI.Box(Rect(Screen.width / 2 - width, Screen.height / 2 - height, 150, 25), ("Pick up the " + Name));
GUI.DrawTexture(Rect(Screen.width/2- width2,Screen.height/2 - height2,75,75), handTexture, ScaleMode.StretchToFill, true, 10.0f);
}
}
**AxeScript**
#pragma strict
var itemPickupSystem : ItemPickupSystem;
var animationvar : Animation;
var rigidbodyVar : Rigidbody;
var axe : Transform;
var axeGO : GameObject;
var target : Transform;
var yOffset : float;
var xOffset : float;
var zOffset : float;
function Start () {
itemPickupSystem = GameObject.FindGameObjectWithTag("Player").GetComponent(ItemPickupSystem);
animationvar = GameObject.FindGameObjectWithTag("Item").GetComponent(Animation);
axeGO = GameObject.FindGameObjectWithTag("Item");
rigidbodyVar = GameObject.FindGameObjectWithTag("Item").GetComponent(Rigidbody);
target = GameObject.Find("TargetToMelee1").transform;
}
function Update () {
if(itemPickupSystem.axeInHands){
axe.parent = target;
axeGO.layer = 11;
axe.localPosition = Vector3(0,0,0);
if(Input.GetButtonDown("Fire1")){
animation.Play("Axe_Melee1", PlayMode.StopAll);
}else{
animation.PlayQueued("Axe_Idle");
}
}else{
axeGO.layer = 10;
axe.parent = GameObject.Find("_Stuffs").transform;
animation.Stop();
}
//Detaches the transform from its parent.
//transform.parent = null;
}
The problem is, when i pickup the axe, the axe grow automatically and irregulary AND I DON’T KNOW WHY:
I checked the parents, parents’ scale doesn’t change AT ALL!FTW!
Can someone help me?!