Monday, 17 February 2014

Weeping angels script part 2

Rrewriting weeping angels script from Javascript to C# and making it work was a piece of cake.. On the other hand, changing player's position back to the start after the weeping angels touch the player, which seemed easy at the beginning, was much more difficult than I thought... At first it seems all i need to do is check if the cube position is the same as player's position and then "simply" change the position of game object... I couldn't be more wrong..

After two days spent writing this script I finally managed to make it work  almost in the way I want it to work... The solution I found was to make function check for collisions(I found basic script to do that), from that script I only took general functions:

(example taken from  website)
function OnCollisionEnter(theCollision : Collision)\
{
    if(theCollision.gameObject.name == "Floor")
    {
    }
}

Which I still had to convert to C# and then change all variables to what I needed.
But this was the easiest way after couple hours reading through Unity Scripts reference for rayCasting functions(not really helpful) and then through OnCollisionEnter functions: partialy helpful-only thing I did wrong was to call these functions in wrong place...

In the end all I needed to add was about two lines of code... Hopefully next scripts won't take me so much time-it may be a good idea to follow a tutorial for most of it :)





No comments:

Post a Comment