コード例 #1
0
    public override void Start()
    {
        base.Start();

        RailManager rm    = GameManager.Instance.RailManager;
        int         index = Random.Range(0, RailManager.NumRails);

        // List<int> availableRails = Enumerable.Range(0, 3).ToList();

        ConnectToRail(rm.GetRail(index));
        for (int i = 0; i < AttachedRail.RailSegmentPositions.Count - 1; i++)
        {
            var screenPos = mainCamera.Camera.WorldToViewportPoint(AttachedRail.RailSegmentPositions[i + 1]);
            if (screenPos.x > 0 && screenPos.y > 0 && screenPos.x < 1 && screenPos.y < 1)
            {
                RailIndex = AttachedRail.FindIndex(AttachedRail.RailSegmentPositions[i]);
                break;
            }
        }
        RailNode nextPosition = AttachedRail.GetTargetRailNode(RailIndex);

        transform.position = nextPosition.Position;

        if (!nextPosition.Valid)
        {
            StartFreeMovement();
        }
        else
        {
            target = nextPosition;
        }

        child = transform.GetChild(0);
    }
コード例 #2
0
ファイル: CameraAnchor.cs プロジェクト: pmartin36/RailRider
    public override void SetTarget()
    {
        RailNode nextPosition = AttachedRail.GetTargetRailNode(RailIndex);

        target = nextPosition;

        var dist  = Vector2.Distance(transform.position, target.Position);
        var angle = Vector2.SignedAngle(transform.position - target.Position, target.Direction) * Mathf.Deg2Rad;

        distanceToTarget = dist * Mathf.Abs(Mathf.Cos(angle));
        distanceToCenter = dist * Mathf.Sin(angle);
        targetRotation   = target.Direction;

        while (target.SegmentIndex > this.segmentIndex)
        {
            segmentIndex++;
            GameManager.Instance.RailManager.AddRail();
        }
    }