using UnityEngine;
using System.Collections;
public class MakeTwoPoints3D : MonoBehaviour {
public GameObject cylinderPrefab;
// Use this for initialization
void Start() {
CreateCylinderBetweenPoints(Vector3.zero, new Vector3(10, 10, 10), 0.5f);
}
void CreateCylinderBetweenPoints(Vector3 start, Vector3 end, float width)
{
var offset = end - start;
var scale = new Vector3(width, offset.magnitude/2.0f, width);
var position = start + (offset/2.0f);
Object cylinder = Instantiate(cylinderPrefab, position, Quaternion.identity);
cylinder.transform.up = offset;
cylinder.transform.localScale = scale;
}
// Update is called once per frame
void Update() {
}
}
同じエラー:erorrsトランスフォームは存在しないのですか?両方のライン上
cylinder.transform.up = offset;
cylinder.transform.localScale = scale;
Severity Code Description Project File Line Suppression State Error CS1061 'Object' does not contain a definition for 'transform' and no extension method 'transform' accepting a first argument of type 'Object' could be found (are you missing a using directive or an assembly reference?) MakeTwoPoints3D.cs 23 Active
なぜあなたは 'オブジェクト'として宣言していますか? – SLaks
[ここ](https://unity3d.com/learn/tutorials/topics/scripting/instantiate)を読んだ後、変数 'cylinderPrefab'に基づいてインスタンス化していますが、cylinderPrefabのタイプは' GameObject'なので、これを呼び出します: 'GameObject cylinder = GameObjectとしてインスタンス化する(cylinderPrefab、position、Quaternion.identity);' – Quantic