public void Create(MapHazard hazard, Hazard listHazard) { this.hazard = hazard; flames = new GameObject("Flammes"); flames.transform.SetParent(this.gameObject.transform, true); Vector3 scale = Vector3.one; Vector3 offset = Vector3.zero; if (hazard.iparam[1] == 0) { // -> flammen nach rechts scale.x = 1; } else if (hazard.iparam[1] == 1) { // <- flammen nach links scale.x = -1; offset.x = +1; } Vector3 pos = this.transform.position; // Pivot Center Sprite sprite = listHazard.projectile[0]; // pos.x += scale.x * sprite.bounds.extents.x - sprite.bounds.center.x + offset.x; // pos.x += offset.x + sprite.bounds.extents.x - sprite.bounds.center.x + offset.x * (sprite.bounds.center.x - sprite.bounds.extents.x); // Pivot: ANY! // -> offset = 0 // <- offset = 1 == 32 (tilewidth) pos.x += offset.x + scale.x * (sprite.bounds.extents.x - sprite.bounds.center.x); pos.y += sprite.bounds.extents.y - sprite.bounds.center.y; BoxCollider2D hitArea = flames.AddComponent <BoxCollider2D> (); Vector2 hitAreaOffset = Vector2.zero; hitAreaOffset.x = sprite.bounds.center.x; hitAreaOffset.y = sprite.bounds.center.y; hitArea.offset = hitAreaOffset; Vector2 hitAreaSize = Vector2.zero; hitAreaSize.x = sprite.bounds.size.x; hitAreaSize.y = sprite.bounds.size.y; hitArea.size = hitAreaSize; // // Pivot BottomLeft // pos.x += listHazard.projectile[0].bounds.extents.x - listHazard.projectile[0].bounds.center.x; // pos.y += listHazard.projectile[0].bounds.extents.y - listHazard.projectile[0].bounds.center.y; // Debug.Log (this.transform.position); // Debug.Log (listHazard.projectile[0].bounds); // Debug.Log (listHazard.projectile[0].bounds.size); flames.transform.position = pos; AnimatedTile animTileScript = flames.AddComponent <AnimatedTile> (); animTileScript.Init(listHazard.projectile.ToArray(), 0); SpriteRenderer flameRenderer = flames.GetComponent <SpriteRenderer> (); flameRenderer.sortingLayerName = "Hazards"; //animTileScript.SetAnimation (); flames.transform.localScale = scale; }
public void CreateHazard(Hazard hazard, MapHazard mapHazard) { this.gameObject.layer = LayerMask.NameToLayer("Death"); // TODO hazardCollider = this.gameObject.AddComponent <BoxCollider2D> (); hazardRenderer = this.gameObject.AddComponent <SpriteRenderer> (); hazardRenderer.sprite = hazard.previewSprite; hazardRenderer.sortingLayerName = "Hazards"; this.hazard = hazard; this.mapHazard = mapHazard; Animator anim = this.gameObject.AddComponent <Animator> (); // dparam[0] == velocity // dparam[1] == angle // dparam[2] == radius // dAngle == Angle // iparam[0] == freq // iparam[1] == direction Vector2 colliderSize = Vector2.one; Vector2 colliderOffset = Vector2.one; if (mapHazard.iparam[1] == (short)PirhanaDirection.upwards) { // this.gameObject.transform.position += Vector3.down; //TODO } else if (mapHazard.iparam[1] == (short)PirhanaDirection.downwards) { // this.gameObject.transform.position += Vector3.right; this.gameObject.transform.localScale = new Vector3(1f, -1f, 1f); // Debug.Log (this.ToString () + " HazardType.pirhana_plants_1_target", this); } else if (mapHazard.iparam[1] == (short)PirhanaDirection.toleft) { } else if (mapHazard.iparam[1] == (short)PirhanaDirection.toright) { } if (hazard.type == HazardType.pirhana_plants_0_random) { anim.runtimeAnimatorController = greenShootingPrihanaAnimatorController; colliderOffset.x = 0.5f; colliderOffset.y = 0.75f; colliderSize.x = 1f; colliderSize.y = 1.5f; } else if (hazard.type == HazardType.pirhana_plants_1_target) { anim.runtimeAnimatorController = redShootingPrihanaAnimatorController; colliderOffset.x = 0.5f; colliderOffset.y = 0.75f; colliderSize.x = 1f; colliderSize.y = 1.5f; } else if (hazard.type == HazardType.pirhana_plants_2_animated) { anim.runtimeAnimatorController = redEatingAnimatorController; colliderOffset.x = 0.5f; colliderOffset.y = 1f; // colliderSize.x = 1f; colliderSize.y = 2f; // } else if (hazard.type == HazardType.pirhana_plants_3_animated) { anim.runtimeAnimatorController = greenEatingAnimatorController; colliderOffset.x = 0.5f; colliderOffset.y = 0.75f; colliderSize.x = 1f; colliderSize.y = 1.5f; } anim.applyRootMotion = true; hazardCollider.offset = colliderOffset; hazardCollider.size = colliderSize; }