Пример #1
0
    void OnGUI()
    {
        if (placementObject != null)
        {
            if (HitsObstacle(placementObject.transform.position, placementObject.transform))
            {
                placementObject.GetComponent <PlacementEffect>().ApplyInvalidEffect();
            }
            else

            {
                placementObject.GetComponent <PlacementEffect>().ApplyValidEffect();
            }


            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            int        layerMask = ((1 << LayerMask.NameToLayer("Ground")));
            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, layerMask))
            {
                var finalPosition = GetNearestPointOnGrid(hitInfo.point);



                float objectHeight = placementObject.GetComponentInChildren <Renderer>().bounds.size.y;
                finalPosition.y += objectHeight / 2;
                placementObject.transform.position = finalPosition;
            }
        }
    }
Пример #2
0
    public BaseObject OnToolBarClick(BaseObject obj)
    {
        Vector3 startPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        placementObject = new BaseFactory().CreateUnit(PlayerManager.humanPlayer, obj, startPosition) as BaseBuilding;

        PlacementEffect placementEffect = placementObject.GetComponent <PlacementEffect>();

        if (placementObject.GetComponent <PlacementEffect>() == null)
        {
            placementEffect = placementObject.gameObject.AddComponent <PlacementEffect>();
        }
        placementEffect.Setup();
        return(null); //Should not be used
    }
Пример #3
0
    IEnumerator MoveAlongWayPoints()
    {
        for (int i = 0; i < WayPoints.WayPointsTrans.Length; i++)
        {
            while (Vector3.SqrMagnitude(transform.position - WayPoints.WayPointsTrans[i].position) > 0.2f)
            {
                transform.position = Vector3.MoveTowards(transform.position, WayPoints.WayPointsTrans[i].position, m_Speed * Time.deltaTime);
                yield return(null);
            }
        }
        BaseBuilding basebuilding = FindObjectOfType <BaseBuilding>();

        if (basebuilding != null)
        {
            basebuilding.GetComponent <IDamagable>().TakeDamage(m_Damage);
        }
        EnemyKilled();
        Destroy(gameObject);
    }