Ejemplo n.º 1
0
	public BlockDamaged CreateDamagedBlock(Block MyBlock, Chunk MyHitChunk, Vector3 HitPosition, BlockData MyBlockData) {
		BlockDamaged MyBlockDamaged = new BlockDamaged();
		if (MyBlock == null)
			return MyBlockDamaged;
		MyBlockDamaged.SetBlockIndex(MyBlock.GetBlockIndex());
		
		// spawn the block damage
		GameObject NewBlockDamage = new GameObject();
		NewBlockDamage.transform.position = HitPosition;
		NewBlockDamage.name = "BlockDamage: " + HitPosition.ToString();
		
		NewBlockDamage.AddComponent<BlockDamageGui>();
		MyBlockDamaged.MyBlockDamage = NewBlockDamage.GetComponent<BlockDamageGui>();	// blocks reference to its damage
		MyBlockDamaged.MyBlockDamage.Health = MyBlockData.Health;
		MyBlockDamaged.MyBlockDamage.Defence = MyBlockData.Defence;
		MyBlockDamaged.MyBlockDamage.MyChunk = MyHitChunk;
		MyBlockDamaged.MyBlockDamage.MyBlock = MyBlock;
		MyBlockDamaged.MyBlockDamage.x = Mathf.RoundToInt(HitPosition.x);
		MyBlockDamaged.MyBlockDamage.y = Mathf.RoundToInt(HitPosition.y);
		MyBlockDamaged.MyBlockDamage.z = Mathf.RoundToInt(HitPosition.z);
		MyBlockDamaged.MyBlockDamage.LookAtObject = GetManager.GetMainCamera ().gameObject;//LookAtPlayer;
		//MyBlockDamaged.MyBlockDamage.LookAtObject = gameObject;
		
		Canvas MyBlockDamageCanvas = NewBlockDamage.AddComponent<Canvas>();
		MyBlockDamageCanvas.renderMode = RenderMode.WorldSpace;
		
		RawImage MyHealthBarBackground = NewBlockDamage.AddComponent<RawImage>();
		MyHealthBarBackground.color = new Color32 (100, 0, 0, 155);
		GameObject NewBlockDamageSon = new GameObject();
		RawImage MyHealthBar = NewBlockDamageSon.AddComponent<RawImage>();
		MyHealthBar.color = new Color32(255,0,0,255);
		MyHealthBar.material = GetManager.GetTerrainManager().HealthBarMaterial;
		MyHealthBarBackground.material = MyHealthBar.material;
		NewBlockDamageSon.transform.SetParent (NewBlockDamage.transform);
		NewBlockDamageSon.transform.localPosition = new Vector3 (0, 0, 0);
		// now reset the block
		Terrain.SetBlock (MouseHit, MyBlockDamaged);
		return MyBlockDamaged;
	}