Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject(-1) && !ClickHandler.LeftClickSub())
        {
            RaycastHit hit;
            Ray        ray = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Transform objectHit = hit.transform;
                RTSObj    sel       = objectHit.GetComponentInParent <RTSObj>();
                if (sel != null)
                {
                    Debug.Log(sel.gameObject.name);
                    if (player.selected != null)
                    {
                        deSelect();
                    }
                    select(sel);
                }
                else
                {
                    Debug.Log("Not an RTS obj: " + objectHit.name);
                    //Debug.Log(hit.point.ToString());
                    deSelect();
                }
            }
        }

        if (Input.GetMouseButtonDown(1) && !ClickHandler.RightClickSub())
        {
            if (player.selected != null)
            {
                RaycastHit hit;
                Ray        ray = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    Transform objectHit = hit.transform;
                    RTSObj    sel       = objectHit.GetComponentInParent <RTSObj>();
                    if (sel != null)
                    {
                        Debug.Log("Right Clicked on Obj");
                        if (sel.team != player.team)
                        {
                            player.selected.GetComponent <WeaponsManager>().setTarget(sel);
                            Debug.Log("Targeting: " + sel.name);
                        }
                    }
                    else if (player.selected is IMovable)
                    {
                        IMovable unit = (IMovable)player.selected;
                        unit.moveTo(hit.point);
                        Debug.Log("Moving to" + hit.point.ToString());
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    public void Fire(RTSObj target)
    {
        coolTime = tps;

        GameObject shell  = GameObject.Instantiate(Resources.Load <GameObject>("Shell"));
        Transform  cannon = unit.transform.Find("Tank/Turret_Container/FirePos");
        Vector3    newpos = cannon.position;

        shell.transform.position = newpos;
        shell.transform.LookAt(target.transform);
        Vector3 direction = target.transform.position - shell.transform.position;

        direction = direction.normalized * force;
        shell.GetComponent <Rigidbody>().AddForce(direction, ForceMode.Impulse);
    }
Exemplo n.º 3
0
    public void aa_onRightClick(object sender, EventArgs e)
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            Transform objectHit = hit.transform;
            RTSObj    sel       = objectHit.GetComponentInParent <RTSObj>();
            if (sel != null)
            {
                weapon.Fire(sel);
            }
        }
    }
Exemplo n.º 4
0
    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Hit Obj: " + collision.gameObject.name);
        RTSObj hit1 = collision.gameObject.GetComponent <RTSObj>();
        RTSObj hit  = collision.gameObject.GetComponentInParent <RTSObj>();

        if (hit != null)
        {
            hit.GetComponent <HealthManager>().Hit(1, 1);
        }
        else if (hit1 != null)
        {
            hit.GetComponent <HealthManager>().Hit(1, 1);
        }
        GameObject.Destroy(gameObject);
    }
Exemplo n.º 5
0
 public bool setTarget(RTSObj enemy)
 {
     target = enemy;
     return(true);
 }
Exemplo n.º 6
0
 private void select(RTSObj newObj)
 {
     player.selected = newObj;
     //newObj.GetComponent<Renderer>().material.color = Color.red;
     actBar.onSelectionChanged();
 }