Rounding not working?

I have made a first person rounding system for building and its not really working… The object does not round both position and rotation will randomly make the object go to a weird transform. I do not know what is wrong. I will tell you what I want it to be like though, that a objects position is rounded to the nearest 0.25, and the rotation rounded to the nearest 30 degrees(mainly the y axis). The setup I currently use is: there is a empty object in the players First person transform(0,0,0 local pos), which is not connected to the main camera, then another object which is a child of the empty gameobject, and this one has the rounding script, then as a child of that are all of the buildables. The path for a buildable would be this “Firstperson/BuildableObjects/Rounding/NameOfBuildable”.

The script I am currently using:

using UnityEngine;
using System.Collections;
using System;

public class Rounding : MonoBehaviour {


	void Update(){
		RoundTrans ();
	}

	private void RoundTrans(){
		Vector3 gPos = transform.position;
		gPos.x = (float)Math.Round(gPos.x, MidpointRounding.AwayFromZero) / 4;
		gPos.y = (float)Math.Round(gPos.y, MidpointRounding.AwayFromZero) / 4;
		gPos.z = (float)Math.Round(gPos.z, MidpointRounding.AwayFromZero) / 4;
		transform.position = gPos;
		Vector3 gRot = transform.eulerAngles;
		gRot.y = Mathf.Round (gRot.y / 30) * 30;
		gRot.z = Mathf.Round (gRot.z / 30) * 30;
		transform.eulerAngles = gRot;
	}
}

EDIT: Still does not work, Ive changed the code to what you said, and the rotation for somereason does not round(well a little but only under certain conditions), and the position makes the object go in front the player, then I turn it then clips into him, and then locks and freezes.

To round to the nearest .25, multiple by 4 before rounding, then divide by 4 after rounding.

val = Mathf.Round(val * 4.0f) / 4.0f;

To get to the nearest 30 degrees, divide by 30, round, then multiple by 30:

val = Mathf.Round(val / 30.0f) * 30.0f);

Note that Transform.eulerAngles can change representation, so your code may not get you what you want without more work.

Well… in your script you are rounding your position and THEN divide it by 4…?

Don’t you want to do something like

gPos.x = (float)Math.Round(gPos.x * 4, MidpointRounding.AwayFromZero) / 4;
gPos.y = (float)Math.Round(gPos.y * 4, MidpointRounding.AwayFromZero) / 4;
gPos.z = (float)Math.Round(gPos.z * 4, MidpointRounding.AwayFromZero) / 4;

?