//called by cones when a collision is detected
        public void SpawnObject()
        {
            //read in randomizer
            packageType p = gameObject.GetComponent <Randomizer>().dropPackage();

            if (p != packageType.none)
            {
                Vector3 behindVan = gameObject.GetComponent <Randomizer>().van.transform.position;                            //tail tip of van
                behindVan.x += (gameObject.GetComponent <Randomizer>().van.GetComponent <SpriteRenderer>().bounds.extents.x); //shift the package slightly into the van
                float packageExtentY;

                //spawn the package on truck
                GameObject newPack;

                if (p == packageType.good || alwaysSpawnGoodPackages)
                {
                    newPack = Instantiate(goodPackagePrefab, Vector3.zero, Quaternion.identity);
                    newPack.GetComponent <Package>().pT = packageType.good;
                }
                else
                {
                    newPack = Instantiate(badPackagePrefab, Vector3.zero, Quaternion.identity);
                    newPack.GetComponent <Package>().pT = packageType.bad;
                }

                packageExtentY             = newPack.GetComponent <SpriteRenderer>().bounds.extents.y;
                behindVan.y               += packageExtentY;
                newPack.transform.position = behindVan;

                dropPackageSound.Play();
                newPack.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(25, 100);
            }
        }
示例#2
0
 public Package(packageType type, String message)
 {
     this.type = type;
     this.message = message;
 }