Exemplo n.º 1
0
 // Instancie tous les éléments de l'environnement
 public void AddElement(string typeElement, string nom, Vector3 pos)
 {
     // Chargement des agents
     if (typeElement == "AgentReactif")
     {
         GameObject agentModel = Instantiate(Resources.Load("AgentReactif/AgentReactifv2")) as GameObject;
         AgentReactif.CreateComponent(agentModel, nom, pos);
     }
     if (typeElement == "SupplyZone")
     {
         GameObject supplyZone = GameObject.CreatePrimitive(PrimitiveType.Plane);
         SupplyZone.CreateComponent(supplyZone, nom, pos, new Vector3(pos.x + 1.5f, 0.01f, pos.z + 1.5f));
     }
 }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        var supplyZones = GameObject.FindGameObjectsWithTag("SupplyZone");

        foreach (var zoneGO in supplyZones)
        {
            SupplyZone zone = zoneGO.GetComponent <SupplyZone>();

            if (zone.Type == SupplyZone.SupplyType.Ammo)
            {
                GameObject marker = Instantiate(supplyZoneMarker);
                marker.SetActive(false);
                contactMarkers.Add(marker);
            }
            else
            {
                GameObject marker = Instantiate(supplyZoneFuelMarker);
                marker.SetActive(false);
                contactMarkers.Add(marker);
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        contacts.Clear();

        var cameraBounds   = cameraController.getCameraBounds();
        var cameraPosition = Camera.main.transform.position;

        transform.position = cameraPosition;

        var collider     = gameObject.GetComponent <BoxCollider2D>();
        var colliderSize = collider.size;

        colliderSize.x = cameraBounds.width;
        colliderSize.y = cameraBounds.height;
        collider.size  = colliderSize;

        var supplyZones = GameObject.FindGameObjectsWithTag("SupplyZone");

        foreach (var zoneGO in supplyZones)
        {
            SupplyZone zone = zoneGO.GetComponent <SupplyZone>();

            Vector3        directionVector = new Vector3(transform.position.x - zone.transform.position.x, transform.position.y - zone.transform.position.y, transform.position.z);
            RaycastHit2D[] hits            = Physics2D.RaycastAll(zone.transform.position, directionVector);
            foreach (var hit in hits)
            {
                if (hit.collider != null && hit.collider.gameObject.GetComponent <SupplyZonesHelper>() != null)
                {
                    ContactInfo contact = new ContactInfo();
                    contact.contactPoint = hit.point;
                    contact.contactRay   = (-directionVector).normalized;
                    contact.refZone      = zone;
                    contacts.Add(contact);
                    break; //ignores second
                }
            }
        }
    }