I have a character whose skeleton has a extra bone, rightHandPT, near his hand.
I want to put a sword in this hand, later I will change it so it has to be by code.
using UnityEngine;
using System.Collections;
public class EquipingSystem : MonoBehaviour {
public void Start () {
MountPrefab("rightHandPT", "3D/sword");
}
public void MountPrefab(string mountStr, string prefabStr){
GameObject mount, prefab;
mount=GameObject.Find(mountStr);
prefab=(GameObject)Instantiate(Resources.Load(prefabStr));
prefab.transform.SetParent(mount.transform);
prefab.transform.localPosition = Vector3.zero;
}
}
the model of the sword is in the folder …/3d/sword.fbx .
When I test this code, without the two last lines : SetParent(); and localPosition
everything goes well except that the sword is not linked…I even see “sword(Clone)” in the hierarchy. But with those two last lines, the “sword(Clone)” disappear from the hierarchy and even if I still can see it in my scene, it is still not linked…I even get this message:
Can’t destroy Transform component of ‘sword(Clone)’. If you want to destroy the game object, please call ‘Destroy’ on the game object instead. Destroying the transform component is not allowed.
I cant see my problem, can you help…please