Code or prefabs problems
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
Answer by ouim · Mar 16, 2018 at 03:55 PM
fix it...a night of sleep often resolves my problems... just made my variables global...
Your answer

Follow this Question
Related Questions
Only spawning power ups that the player wants in that game 1 Answer
Problems with instantiating 1 Answer
Can I Create a Prefab in Unity 2018.3.5f1 With C# Script Using a YAML File? 0 Answers
How do i take a grab of clone from prefab and change his velocity 2 Answers
How to interact with multiple instances of a single prefab? 1 Answer