Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float hauteur     = 1.5f;
        float distancemax = 240f;

        if (hand.GetComponent <SteamVR_LaserPointer>().thickness > 0 && toggleDraw)
        {
            if (Dot(normal, hand.transform.forward) != 0)
            {
                float           t            = -(Dot(normal, hand.transform.position) - floor.transform.position.y) / Dot(normal, hand.transform.forward);
                Vector3         intersection = hand.transform.position + hand.transform.forward * t;
                float           distance     = (hand.transform.position - intersection).magnitude;
                IsRoadArguments args         = new IsRoadArguments(intersection);
                city.SendMessage("isRoad", args);
                if (distance <= distancemax && args.answer)
                {
                    GameObject drawing = Instantiate <GameObject>(circle);
                    drawing.GetComponentInChildren <MeshRenderer>().material.color = carColor;
                    drawing.transform.position = new Vector3(intersection.x, intersection.y + hauteur, intersection.z);
                    drawing.SetActive(true);
                    selectedCar.GetComponent <CarMovement>().AddBaowl(drawing);
                    selectedCar.GetComponent <CarMovement>().chemin.Add(drawing.transform.position);
                }
            }
        }
    }
Exemplo n.º 2
0
 private void OnCollisionEnter(Collision collision)
 {
     Debug.Log(collision.collider.gameObject.name);
     if (parking && gameObject.transform.parent != parking.transform && collision.collider.gameObject.name != "BodyCollider" && collision.collider.gameObject.name != "HeadCollider")
     {
         IsRoadArguments args = new IsRoadArguments(this.transform.position);
         CityGenerator.SendMessage("isRoad", args);
         if (!args.answer)
         {
             Destroy(this.gameObject);
         }
         else
         {
             gameObject.transform.localScale = new Vector3(2, 2, 2);
             gameObject.transform.position   = gameObject.transform.position + new Vector3(0, 0, 0);
             if (!gameObject.GetComponent <CarMovement>().togglemove)
             {
                 CarTransformArgs carArgs = new CarTransformArgs(gameObject.transform);
                 CityGenerator.SendMessage("getCarTransformOnRoad", carArgs);
             }
             gameObject.GetComponent <Rigidbody>().velocity        = new Vector3(0, 0, 0);
             gameObject.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0);
         }
     }
 }
Exemplo n.º 3
0
    void isRoad(IsRoadArguments args)
    {
        if (args.position.x > 0 || args.position.z < 0)
        {
            args.answer = false;
            return;
        }
        int x = -(int)args.position.x / 20;
        int y = (int)args.position.z / 20;

        if (cityMap[x + y * mapWidth] == CityObject.R)
        {
            args.answer = true;
        }
        else
        {
            args.answer = false;
        }
        Debug.Log(args.position.x + "," + args.position.z + " : " + x + ", " + y + " " + args.answer);
    }
Exemplo n.º 4
0
    void getCarTransformOnRoad(CarTransformArgs args)
    {
        IsRoadArguments argsIs = new IsRoadArguments(args.transform.position);

        isRoad(argsIs);
        if (argsIs.answer)
        {
            int x = -(int)args.transform.position.x / 20;
            int y = (int)args.transform.position.z / 20;

            int relativeX = -(int)args.transform.position.x % 20;
            int relativeY = (int)args.transform.position.z % 20;

            Debug.Log(relativeX + " " + relativeY);

            RoadType r = getRoadType(x, y);
            switch (r)
            {
            case RoadType.DEAD_END_LEFT:
            case RoadType.DEAD_END_RIGHT:
            case RoadType.STRAIGHT_H:
                if (relativeY <= 10)
                {
                    args.transform.rotation = Quaternion.Euler(0, 90, 0);
                }
                else
                {
                    args.transform.rotation = Quaternion.Euler(0, -90, 0);
                }
                break;

            case RoadType.DEAD_END_DOWN:
            case RoadType.DEAD_END_UP:
            case RoadType.STRAIGHT_V:
                if (relativeX <= 10)
                {
                    args.transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                else
                {
                    args.transform.rotation = Quaternion.Euler(0, 180, 0);
                }
                break;

            case RoadType.CROSS:
                break;

            case RoadType.TRI_UP:
                if (relativeY <= 3)
                {
                    if (relativeX <= 10)
                    {
                        args.transform.rotation = Quaternion.Euler(0, 0, 0);
                    }
                    else
                    {
                        args.transform.rotation = Quaternion.Euler(0, 180, 0);
                    }
                }
                else if (relativeX <= 10)
                {
                    args.transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                else
                {
                    args.transform.rotation = Quaternion.Euler(0, 180, 0);
                }
                break;

            case RoadType.TRI_DOWN:
                if (relativeY >= 17)
                {
                    if (relativeX <= 10)
                    {
                        args.transform.rotation = Quaternion.Euler(0, 0, 0);
                    }
                    else
                    {
                        args.transform.rotation = Quaternion.Euler(0, 180, 0);
                    }
                }
                else if (relativeX >= 10)
                {
                    args.transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                else
                {
                    args.transform.rotation = Quaternion.Euler(0, 180, 0);
                }
                break;
            }
        }
    }