public override void Start() { collidesWith = Physics2D.GetLayerCollisionMask(gameObject.layer); globalDirection = (transform.parent.lossyScale.x < 0) ? -1 : 1; //needed to get the parent transform lossyScale to determine firing side if (Screen.width > Screen.height) { maxDistance = (int)(Screen.width + Screen.width / 4f) * globalDirection; } else { maxDistance = (int)(Screen.height + Screen.height / 4f) * 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); ppu = mainGo.GetComponent <SpriteRenderer>().sprite.pixelsPerUnit; }
void Awake() { var rend = GetComponent <SpriteRenderer>(); anim = new BasicAnimation(ref rend, ref Frames); anim.flickerSkipFrames = FlickerSkipFrames; scale = transform.localScale; }
public override void InitialSet() { base.InitialSet(); if (RandomStartFrame) { int randIndex = (int)Random.Range(0, Frames.Length - 1); anim = new BasicAnimation(ref rend, ref Frames, randIndex); } else { anim = new BasicAnimation(ref rend, ref Frames); } }
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); }
protected virtual void Start() { var rend = GetComponent <SpriteRenderer>(); anim = new BasicAnimation(ref rend, ref Frames); }