前提・実現したいこと
現在、2dのアクションゲームを作っています。アクションゲームのキャラに
リンクのような剣の振り方をさせたくて、剣をプレイヤーを軸にして回転がさせたいです。
親子関係にすると親が軸になるというのをみたので
prefab.transform.parent = transformでスクリプトで親子関係を作りたいのですがうまくいきません
エラーによるとスクリプトによるおや子関係は無効化されているみたいです。
発生している問題・エラーメッセージ
Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'Sword'). UnityEngine.Transform:set_parent (UnityEngine.Transform)
該当のソースコード
public GameObject swordPrefab; public GameObject playerObject; Rigidbody2D rb; // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { } void FixedUpdate(){ if(Input.GetKey(KeyCode.Space)){ Instantiate(swordPrefab, transform.position, Quaternion.Euler(0,0,-40)); swordPrefab.transform.parent = transform; } }
試したこと
SetParentにしてみたり(今回のやり方では相応しくない感じです
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。