コード例 #1
0
    //public void SpawnNewSegment()
    //{
    //	int segmentUse = Random.Range(0, prefabList.Length);

    //	TrackSegment segmentToUse = prefabList[segmentUse];
    //       TrackSegment newSegment = Instantiate(segmentToUse, Vector3.zero, Quaternion.identity);


    //       Vector3 currentExitPoint;
    //	Quaternion currentExitRotation;
    //	if (m_Segments.Count > 0)
    //	{
    //		m_Segments[m_Segments.Count - 1].GetPointAt(1.0f, out currentExitPoint, out currentExitRotation);
    //	}
    //	else
    //	{
    //		currentExitPoint = transform.position;
    //		currentExitRotation = transform.rotation;
    //	}

    //	newSegment.transform.rotation = currentExitRotation;

    //	Vector3 entryPoint;
    //	Quaternion entryRotation;
    //	newSegment.GetPointAt(0.0f, out entryPoint, out entryRotation);


    //	Vector3 pos = currentExitPoint + (newSegment.transform.position - entryPoint);
    //	newSegment.transform.position = pos;
    //	newSegment.manager = this;

    //	newSegment.transform.localScale = new Vector3(1, 1, 1);
    //	newSegment.objectRoot.localScale = new Vector3(1.0f/newSegment.transform.localScale.x, 1, 1);

    //       if (m_SafeSegementLeft <= 0)
    //           SpawnDifferencies(newSegment);
    //       else
    //           m_SafeSegementLeft -= 1;

    //       m_Segments.Add(newSegment);
    //}

    //   public void SpawnDifferencies(TrackSegment segment)
    //   {

    //       if (segment.possibleDifferencies.Length != 0)
    //       {
    //           for (int i = 0; i < segment.possibleDifferencies.Length; ++i)
    //           {
    //               //segment.possibleDifferencies[Random.Range(0, segment.possibleDifferencies.Length)].Spawn(segment, segment.differencePositions[i]);
    //               segment.possibleDifferencies[i].Spawn(segment, Random.value > 0.5 ? true : false);
    //           }
    //       }
    //   }

    public void SpawnNewSegment()
    {
        totalSegmentCount++;

        TrackSegment newSegment = Instantiate(trackSeg);

        newSegment.name = totalSegmentCount.ToString();
        newSegment.GenerateSegment();


        Vector3    currentExitPoint;
        Quaternion currentExitRotation;

        if (m_Segments.Count > 0)
        {
            m_Segments[m_Segments.Count - 1].GetPointAt(1.0f, out currentExitPoint, out currentExitRotation);
        }
        else
        {
            currentExitPoint    = transform.position;
            currentExitRotation = transform.rotation;
        }

        newSegment.transform.rotation = currentExitRotation;

        Vector3    entryPoint;
        Quaternion entryRotation;

        newSegment.GetPointAt(0.0f, out entryPoint, out entryRotation);


        Vector3 pos = currentExitPoint + (newSegment.transform.position - entryPoint);

        newSegment.transform.position = pos;
        newSegment.manager            = this;

        m_Segments.Add(newSegment);
    }