Can someone point me in the right direction to find out how to do this. I have googled multiple ways but come up with everything but what Im looking for.
I have paper rock scissors…right
Paper>rock
rock>scissors
scissors>paper…
if i had each of them a gameobject on a chessboard and placed the rock next to the scissor how can I set them to know that rock beat scissor? Then I want them both to remain on the board and i put paper down next to rock and beat that one. each time one is beat it stays in gameworld but turns texture color.
not looking for code just maybe somewhere I can research this.
thx
I suppose you have some kind of array representation of your chessboard?
If so you could check the surrounding indices for other gameobjects.
And at the simplest form you could have 2 strings, one called ‘beatenBy’ the other one ‘beats’.
Then you create 3 prefabs, one for each kind and set the strings accordingly.
Then you could check if ‘beats’ of the gameobject you placed is the same as ‘beatenBy’ of the surrounding objects.
The array idea is probably the best.
Another, less optimal way i can think of would be to let each object do a spherecast around itself in a certain radius and sendMessage(“Challenge”, sourcetype) to every qualified object hit.
The other object then evaluates this (if sourcetype beats mytype → SetBeaten()).
Okay so this isnt right nor have I even tried to see if this works but this is what I am thinking just may have to tweak the script to get it to work but on the right path?
var element : GameObject;
var playerColor : GameObject;
var opponatePlayerColor : GameObject;
var beaten : boolean;
var AOE : int;
var player1 : boolean;
function Start ()
{
if(player1);
{
set player1 = playerColor;
}
animation.Play("flame");
}
function Update ()
{
if(Physics.CheckSphere(transform.position, AOE))
{
animation.Play("flameburn", PlayMode.StopAll);
}
if(element = beaten.false)
{
playerColor.renderer.material.color = playerColor.renderer.material.color;
}
else if(element = beaten.true)
{
playerColor.renderer.material.color = opponatePlayerColor.renderer.material.color;
}
}
You have quite some errors in your script.
I thought about something like this(c# / untested):
public enum BeatenBy{
rock,
paper,
scissor
}
public class ChallengeInfo {
public ChallengeInfo(GameObject thischallenger, BeatenBy challengerType) {
challenger = thischallenger;
type = challengerType;
}
public GameObject challenger;
public BeatenBy type;
}
public BeatenBy beatsMe; //set this to whatever beats this in the inspector
public BeatenBy IBeat; //set this to whatever is beaten by this
public LayerMask scannedLayer; //set this to the layer of the objects to be evaluated in the inspector
public float scanRadius; //this is the radius in which other objects are found
void Update() {
Collider[] cols = Physics.OverlapSphere(transform.position, scanRadius, scannedLayers)
foreach (Collider col in cols) {
col.sendMessage("Challenge", new ChallengeInfo(this.gameObject, IBeat), SendMessageOptions.DontRequireReceiver);
}
}
bool alreadyBeaten = false;
public void Challenge(ChallengeInfo info) {
if (alreadyBeaten == false info.type == beatsMe) {
alreadyBeaten = true;
//Do whatever you need if this gameobject has been beaten. info.challenger is the one that beat this, if needed
}
}