Example #1
0
    void Start()
    {
        if (BUILDINGROOF_LAYER_MASK == -1)
        {
            BUILDINGROOF_LAYER_MASK = LayerMask.GetMask(new string[] { "BuildingRoof" });
        }

        RaycastHit hit;
        bool       buildingWasHit = Physics.Raycast(transform.position, Vector3.forward, out hit, 40f, BUILDINGROOF_LAYER_MASK);

        // Subscribe to know who are going here
        PubSub.subscribe("TargetPOI(" + node.Id + "):Add", this);
        PubSub.subscribe("TargetPOI(" + node.Id + "):Remove", this);
        PubSub.subscribe("gameIsReady", this);

        // Add InformationPOI, since we now have inited this icon
        this.gameObject.AddComponent <InformationPOI>();

        // Get small and big icon gameobjects
        bigIcon   = Misc.FindDeepChild(transform, "icon-big").gameObject;
        smallIcon = Misc.FindDeepChild(transform, "icon-small").gameObject;

        // Set big icon material
        MeshRenderer bigIconMeshRenderer = bigIcon.GetComponent <MeshRenderer> ();

        bigIconMeshRenderer.material = groupMaterials[group];

        isFalling = true;
        Game.instance.addInitAnimationRequest();

        if (buildingWasHit)
        {
            BuildingRoof buildingRoof = hit.transform.gameObject.GetComponent <BuildingRoof> ();
            // Land on the building
            targetZ = -buildingRoof.getTargetHeight() - DISTANCE_FROM_ROOFTOPS;
        }
        else
        {
            // Land on the ground
            targetZ = -0.1f - DISTANCE_FROM_ROOFTOPS;
        }

        // Set random velocity
        fallSpeed = Misc.randomPlusMinus((transform.position.z - targetZ) / 3f, 1f);
    }