Thank you for replying
@Kurt-Dekker I understand most of the steps but not fully, however
@PraetorBlue Please find the code below
My goal in this code is to set an action for each material selected
for ex: Explosive gives the character self destruction power-up etc.
The error I keep getting is "
cs(6,7): error CS0138: A ‘using namespace’ directive can only be applied to namespaces; ‘Material’ is a type not a namespace. Consider a ‘using static’ directive instead
" I can’t seem to figure it out, please note am still a beginner
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
using UnityEngine.Material;
public class PowerUpManager : MonoBehaviour
{
public Material Frwrdmat;
public Material Backwrdmat;
public Material Destmat;
public Material Magmat;
public Material LasrMat;
public Material ExploMat;
public class PowerUp
{
public enum Type
{
BoostFwd,
BoostBack,
Destruction,
Magnet,
Projectiles,
Explosion,
ExtraLife,
Slowdown
}
public Type _type;
private float _duration;
public GameObject _object;
public Material _material;
private Color _color;
public PowerUp(Type type, float duration, GameObject obj, Color color, Material material)
{
_type = type;
_duration = duration;
_object = obj;
_color = color;
_material = material;
}
private Color GetColorByType(PowerUp.Type type)
{
switch (type)
{
case PowerUp.Type.ExtraLife: return LifeColor;
case PowerUp.Type.Slowdown: return SlowColor;
default:
throw new ArgumentOutOfRangeException("type", type, null);
}
}
private Material GetMaterial(PowerUp.Type type)
{
switch (type)
{
case PowerUp.Type.BoostFwd: return Frwrdmat;
case PowerUp.Type.BoostBack: return Backwrdmat;
case PowerUp.Type.Destruction: return Destmat;
case PowerUp.Type.Magnet: return Magmat;
case PowerUp.Type.Projectiles: return LasrMat;
case PowerUp.Type.Explosion: return ExploMat;
default:
throw new ArgumentOutOfRangeException("type", type, null);
}
}
private void SpawnPowerUp()
{
var newPowerUpY =
RoundToMultipleOfN(_distanceBetweenPlatforms,
Random.Range(_minSpawnY, _maxSpawnY)) +
(float)_distanceBetweenPlatforms / 2;
var newPowerUpParentObj = Instantiate(PowerUpParentPrefab,
new Vector3(_spawnPosX, newPowerUpY, 0), Quaternion.identity);
var newPowerUpObj = Instantiate(PowerUpPrefab,
new Vector3(_spawnPosX, newPowerUpY, 0), Quaternion.identity,
newPowerUpParentObj.transform);
newPowerUpObj.tag = "PowerUp";
newPowerUpParentObj.tag = "PowerUp";
var newType =
PowerUp.RandomType(_platformManager.PlatformSpeed,
_playerAnimationParent);
newPowerUpObj.GetComponent<Renderer>().material.SetColor("_Color",
GetColorByType(newType));
var newPowerUpDuration = GetDurationByType(newType);
switch (newType)
{
case PowerUp.Type.ExtraLife:
case PowerUp.Type.Slowdown:
newPowerUpObj.GetComponent<Animator>()
.Play("Flashing");
break;
case PowerUp.Type.BoostFwd:
case PowerUp.Type.BoostBack:
case PowerUp.Type.Destruction:
case PowerUp.Type.Magnet:
case PowerUp.Type.Projectiles:
case PowerUp.Type.Explosion:
default:
newPowerUpObj.GetComponent<Animator>()
.Play("PowerUpState");
break;
}
newPowerUpParentObj.GetComponent<PowerUpScript>().SlowdownFactor =
SlowdownFactor;
PowerUps.Add(new PowerUp(newType, newPowerUpDuration,
newPowerUpParentObj,
newPowerUpObj.GetComponent<Renderer>().material.color));
}