public override void Start() { base.Start(); maxDistance = (CalcObject.getMaxScreenDistance() + AddedMaxDistance) * ppu * globalDirection; originGo = initLaserParts(new GameObject("Origin"), new Vector2(0, 0), OriginImg); mainGo = initLaserParts(new GameObject("Main"), new Vector2(originGo.GetComponent <SpriteRenderer>().sprite.bounds.size.x *globalDirection, 0), MainImg); tipGo = initLaserParts(new GameObject("Tip"), new Vector2(0, 0), TipImg); originAnim = initAnimations(originGo, OriginImg); mainAnim = initAnimations(mainGo, MainImg); blastAnim = initAnimations(tipGo, BlastImg); tipAnim = initAnimations(tipGo, TipImg); }
private GameObject initLaserMain(GameObject main, Vector3 initPosition, Sprite[] sprite, int sort) { main.transform.parent = this.transform; main.transform.localPosition = initPosition; main.transform.localScale = new Vector3(main.transform.localScale.x * globalDirection, main.transform.localScale.y); main.transform.rotation = new Quaternion(); int chunksNeeded = (int)((CalcObject.getMaxScreenDistance() / MainImg[0].bounds.size.x) + AddedMaxDistance); mainAnims = new BasicAnimation[chunksNeeded]; int startFrame = 0; for (int i = 0; i < chunksNeeded; i++) { GameObject chunk = new GameObject("Chunk" + i); chunk.transform.parent = main.transform; chunk.transform.localPosition = new Vector2(sprite[0].bounds.size.x * i, 0); chunk.transform.localRotation = new Quaternion(); chunk.transform.localScale = new Vector2(1, 1); SpriteRenderer chunkSprite = chunk.AddComponent <SpriteRenderer>(); chunkSprite.sprite = sprite[startFrame]; chunkSprite.sortingOrder = sort + UniqueMaskId; chunkSprite.sortingLayerName = sortLayer; chunkSprite.color = FiringScript.SpriteColor; chunkSprite.maskInteraction = SpriteMaskInteraction.VisibleInsideMask; mainAnims[i] = new BasicAnimation(ref chunkSprite, ref MainImg, startFrame); startFrame++; if (!StaggerAnimations || startFrame > sprite.Length - 1) { startFrame = 0; } } maxDistance = chunksNeeded * MainImg[0].bounds.size.x * ppu * globalDirection; mainMask = initMask(main, "MainMask", new Vector2(0, 0), new Vector2(1, MainMaskYScale), sortOrder, sortOrder - 1); return(main); }