示例#1
0
    private void CreateObstaclePrefab()
    {
        Object newPrefab = PrefabUtility.CreateEmptyPrefab("Assets/Prefabs/Obstacles/" + objectName + ".prefab");

        GameObject newObject = new GameObject();

        SpriteRenderer sr = newObject.AddComponent <SpriteRenderer>() as SpriteRenderer;

        sr.sprite = singleSprite;

        BoxCollider2D bc = newObject.AddComponent <BoxCollider2D>() as BoxCollider2D;

        bc.size = singleSprite.bounds.size;

        GameObject path = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Path.prefab", typeof(GameObject));

        GameObject pathInstance = (GameObject)Instantiate(path, newObject.transform.position, Quaternion.identity);

        pathInstance.transform.parent = newObject.transform;

        followPath fp = newObject.AddComponent <followPath>() as followPath;

        fp.path = pathInstance.GetComponent <definePath>();

        obstacleAI ai = newObject.AddComponent <obstacleAI>() as obstacleAI;

        PrefabUtility.ReplacePrefab(newObject, newPrefab, ReplacePrefabOptions.ConnectToPrefab);

        DestroyImmediate(newObject);

        this.Close();
    }
    void Start()
    {
        //create a chaser and flock unit on each path
        for (int i = 0; i < paths.Count; ++i)
        {
            //first we create the chaser
            Vector3    startPos = paths[i].GetComponent <pathPoints>().points[25];
            GameObject chaser   = (GameObject)Instantiate(chaserPrefab, startPos, Quaternion.identity);
            //manually initialize the chaser's followPath component with the desired properties
            followPath fp = chaser.GetComponent <followPath>();
            fp.path  = paths[i];
            fp.curPt = 25;
            fp.init();

            //now we create as many flock units as desired
            for (int r = 0; r < numUnitsPerFlock; ++r)
            {
                GameObject flockUnit = (GameObject)Instantiate(flockUnitPrefab, startPos, Quaternion.identity);
                flockUnit.GetComponent <SpriteRenderer>().sprite = flockSprites[i];
                //initialize the flock unit's followChaser component with the desired properties
                followChaser fc = flockUnit.GetComponent <followChaser>();
                fc.leader = chaser;
                fc.init();
                //ofset each flock unit by a different amount, so that they do not begin on top of each other
                Vector3 curPos = fc.transform.position;
                fc.transform.position = new Vector3(curPos.x + .4f * (numUnitsPerFlock / 2f + .5f - r), curPos.y, curPos.z);
                //give each flock unit a tag so we can poll through them for collisions
                flockUnit.tag = "flockUnit";
            }
        }
    }
示例#3
0
    private bool questionCorrect;                                                       // did you get the question correct

    void Start()
    {
        bossAnim         = GetComponent <Animator> ();                          // get the animator on the boss
        question         = panel.GetComponent <Animator>();                     // get the animator on the question panel
        bulletDamage     = health / shotsToKill;                                // set the bullet damage
        bossPath         = GetComponent <followPath>();                         // find the path the boss needs to follow
        bossPath.enabled = false;                                               // disble the path follow
        bossAnim.enabled = false;                                               // disable the boss animator
        question.enabled = false;                                               // disable the question animator
    }
示例#4
0
    public static void combinePlayerWithPath(Player p, List <AdvancedPosition> advancedPath, Material mat, int round)
    {
        float scaleFactor = 20;

        List <Vector3> path  = new List <Vector3>();
        List <float>   viewX = new List <float>();
        List <float>   viewY = new List <float>();

        foreach (AdvancedPosition item in advancedPath)
        {
            path.Add(item.GetPosition().castToUnityVector3());
            viewX.Add(item.GetOrientationX());
            viewY.Add(item.GetOrientationY());
        }

        GameObject map = GameObject.FindGameObjectsWithTag("map")[0];

        //TODO turn model 180 degrees |imported wrong way around | DID NOT FIX
        GameObject player = GameObject.Instantiate(Resources.Load <GameObject>("visualization models/player_char"));

        player.tag  = "Player";
        player.name = p.Name;

        foreach (var item in player.transform.GetComponentsInChildren <Renderer>())
        {
            item.material = mat;
        }

        player.transform.localScale = Vector3.one * scaleFactor;
        player.transform.SetParent(map.transform);
        player.transform.position = path[0];

        player.AddComponent <followPath>();
        followPath followScript = player.GetComponent <followPath>();

        string pathName = player.name + " path " + "round: " + round;

        followScript.pathToFollow = createPathFromListVector3(path, pathName, mat.color);
        followScript.pathToFollow.viewDirectionX = viewX;
        followScript.pathToFollow.viewDirectionY = viewY;
        followScript.seperateYRotation           = player.transform.GetChild(1).gameObject;

        //adjust to tickrate
        followScript.tickRate = 32;
    }