Puzzle Coding Issue

Hey everyone,

Sorry if this seems simple, I just started coding with Unity and I’m having some issues. I’ve looked at Unity Answers, though I thought I found a solution, but it hasn’t helped. What I’m trying to do is to build a puzzle that’s similar to that of Skyrim. The one that has the three rings and you have to rotate them with the claw in the middle. The only thing that’s different with my puzzle is I have a sphere in the middle, which would rotate and you would get the key.

So, my issue is I can get all three of the rings to play only one rotate animation. I’m really not sure how to get the other animations working on it. I’ve set the animation size to 4 since there’s 4 animations, so that isn’t the issue.

This is my working script:

//BigRing
var inRange : boolean = false;

var rotateRight : boolean = false;

var BigRing : GameObject;

var animationNumber = 1;

function Update () {

if ((inRange == true)  (_Master.isActive == true)) {

if (animationNumber == 1) {

print("You Rotated Right");
BigRing.animation.Play("RotateO");
animationNumber ++;
rotateRight = true;

}

if (animationNumber == 2){

print("You Rotated Right");
BigRing.animation.Play("RotateG");
animationNumber ++;
RotateRight = true;
}

if (animationNumber == 3){

print("You Rotated Right");
BigRing.animation.Play("RotateS");
animationNumber ++;
RotateRight = true;

}

if (animationNumber == 4){

print("You Rotated Right");
BigRing.animation.Play("RotateM");
animationNumber ++;
RotateRight = true;

}

}

}
function OnTriggerEnter(OuterRing : Collider){

if (OuterRing.gameObject.tag == "Player"){

print ("Done");
inRange = true;

}

}

function OnTriggerExit (OuterRing : Collider) {

if (OuterRing.gameObject.tag == "Player"){

inRange = false;

}

}

//MasterScript

static var isActive : boolean = false;

function Update () {

if(Input.GetKeyDown("e")){

print ("Activate");
isActive = true;


}else {

isActive = false;

}

}

This is what the Puzzle looks like. I need it to rotate from M, to O, to G, to S. Same for the other rings, but once I have the code for one of them, the others will be just copy paste of the code.

[ code][/code]

Sorry, it has been fixed.

Why don’t you try having 2 different scripts. 1 script will be placed on each of the 3 rings. It will simply rotate the ring 90 degress when it gets a click event. The other script will check the values of the other 3 scripts and do whatever when the center is clicked.

I got bored, so I decided to have a hack at this.

using UnityEngine;
using System.Collections;

public class RotateOnClick : MonoBehaviour {
	public int position = 1;
	public int positions = 4;

	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
	}
	
	void OnMouseUp() {
		position++;
		if(position > positions) {
			position = 1;
		}
		
		RotateToPosition(position);
	}
	
	void RotateToPosition(int newPosition) {
		Vector3 tempRotation = gameObject.transform.rotation.eulerAngles;

		this.gameObject.transform.rotation = Quaternion.Euler(
			new Vector3(
				(360/positions)*(position-1),
				tempRotation.y,
				tempRotation.z
			)
		);
	}
}

This code gets placed on each of the rings. It doesn’t use animations like yours does, so you’ll have to replace ‘RotateToPosition’ with your animation code.

You’ll also need to write a script for the center that checks the positions of the rings.

Thank you, wccrawford. I will try this right now and see if it works.
To answer your question though I am using 3 different scripts for my rings, one for each of the rings.