public override void use() { stimulus zap = stimulus.spawn(stimulusType.electric, myPlayer.transform.position, myPlayer.lookDirection, 0); zap.speed = zapSpeed; zap.lifeTime = zapTime; }
private void OnCollisionEnter(Collision col) { GameObject obj = col.gameObject; switch (obj.tag) { case "stimulus": stimulus cStim = col.gameObject.GetComponent <stimulus>(); if (myType == stimulusType.water) { if (cStim.myType == stimulusType.electric) { electrified = true; } } if (myType == stimulusType.fire) { if (cStim.myType == stimulusType.water) { Destroy(gameObject); } } break; case "environmentalObject": case "environmentSwitch": speed = 0f; break; } }
public void environmentCollisions() { Bounds b = GetComponent <Collider>().bounds; float r = boundsRadius(b); Collider[] col = Physics.OverlapSphere(b.center, r); foreach (Collider c in col) { GameObject obj = c.gameObject; if (obj == gameObject) { continue; } switch (obj.tag) { case "stimulus": stimulus cStim = obj.GetComponent <stimulus>(); if (conductive && cStim.electrified) { electrified = true; } if (cStim.myType == stimulusType.water) { if (waterDestructible) { Destroy(gameObject); } onFire = false; wet = true; } else { wet = false; } if (burnable && cStim.hot && !wet) { onFire = true; } break; case "environmentalObject": environmentalObject cE = obj.GetComponent <environmentalObject>(); if (cE.electrified && conductive) { electrified = true; } break; } } }
public static stimulus spawn(stimulusType t, Vector3 pos, Vector3 dir, float randomRange) { float dx = Random.Range(dir.x - randomRange, dir.x + randomRange); float dy = Random.Range(dir.y - randomRange, dir.y + randomRange); float dz = Random.Range(dir.z - randomRange, dir.z + randomRange); GameObject newStimObj = (GameObject)Instantiate(Resources.Load("stimulus")); newStimObj.transform.position = pos; stimulus newStim = newStimObj.GetComponent <stimulus>(); newStim.myType = t; newStim.moveDirection = new Vector3(dx, dy, dz).normalized; return(newStim); }